murgatroid99
murgatroid99

Reputation: 20297

Download files from ASP forms with Python

I am attempting to download a lot of files from http://www.sl.universalservice.org/funding/opendatasearch/Search1.asp using the Python library mechanize. On the site, the user must fill out 2 ASP forms, and then when the user clicks the second submit button, a file download starts. I was able to get the Python program to go through both forms, but I do not see how to get the file. How can I access the file once I submit the second form?

Upvotes: 0

Views: 598

Answers (1)

Thomas K
Thomas K

Reputation: 40370

With b as your browser object:

b.submit()  # The second of the two forms
c = csv.DictReader(b.response(), dialect='excel-tab')

b.response() gives you access to a file-like object, which can be processed by the csv module.

Upvotes: 1

Related Questions