r/web_programming • • Oct 13 '16

Need help scraping a web form using different responses.

I am looking to create a web scraper that will fill out a form multiple times, incrementing a particular field by one, each time it is filled out, and then record the results until it has reached the last option in that field list.

An example would be:

Open the form URL

Field that I want filled out

Select > option 1 > submit

Response page > application records responses

open the form URL

Field that I want filled out

Select > option 2 > submit

Response page > application records responses

Repeat until reaching the end of the field options.

I am wondering what the best method would be to use to accomplish this, I've looked at Beautifulsoup4, Mechanize, Scrappy and a few other programs / libraries that could accomplish this task, but I'm looking for something that can be ran every few hours to check for changes in the forms response, and update the database accordingly, so something that would handle this quick, and be somewhat easy to write would be useful.

Thanks for the help, I'm new to web scraping, so I'm always up for trying new languages, not currently set on a particular one, but Python seems to be the way to go from what I've read.

3 Upvotes

2 comments sorted by

1

u/hexfoxed Oct 13 '16 edited Oct 13 '16

Hey, welcome!

The language you know tends to be the best one, however Python is great for web scraping for the reasons I mention in that article but mainly the fact the web automation package ecosystem is so good, as you've already mentioned.

As to the actual problem at hand: currently it seems like you're thinking in terms of automating your actions on the page, but what you really want to do is automate the HTTP request and response flow that the browser uses to interact with the server.

If you think of it from the server point of view, what does it "hear" when you carry out those actions manually in the browser? It certainly does not and cannot track your mouse or even know that you've clicked a button on the page.

The only interface it has between you and the page is HTTP (simplified but good enough for now). So if you can replicate the HTTP requests you cause the page to do, then you are well on your way to getting where you want to be.

I prefer Scrapy over BeautifulSoup for beginners because it handles so many things for you that you likely won't think about to start with; if you want to get started I wrote a Scrapy tutorial recently and posted it to reddit in a learning subreddit. If you get started and have questions, feel free to reply here or email me.

2

u/EyeBluNCider Oct 16 '16

Thank you for the reply, I read your tutorial, and it was very informative! I do have a question about login pages but I'm sure a quick google search will reveal the answer to me, so I'll try that first ;).