質問

Okay, so I'm starting to get a little frustrated. I've spent most of a day trying to figure out why my script is not working - both on github and here. It should be fairly simple. Mechanize load a page, fill in a form, submit the form, opens a new page with company information and post the content. It's just not working. When I check the code, I can see, that the right form is filled out, but after mechanize submits the form it doesn't go to the new page but stay's on the one, where it filled out the form. Code is like this:

from mechanize import Browser

br = Browser()

url = "http://cvr.dk/Site/Forms/CMS/DisplayPage.aspx?pageid=0"

cvr = br.open(url).read()

#I select the form
br.select_form(name="aspnetForm")

#I fill in 19997049 as a company number
br.form['ctl00$QuickSearch1$CvrTextBox'] = "19997049"

response = br.submit()

content = response.read()

print content

I have a feeling it's extremely simple, but that I'm missing something with the redirect that should happen, when the form is submitted.

EDIT: It seems like there's alot of javascripts on the site. Might that be the reason? And when what a the options like?

EDIT2: Okay, it seems that I can simply add the company number in the url and get the page that I want that way, but I'm still puzzled as to why this script doesn't work.

Thanks a bunch for any feedback

役に立ちましたか?

解決

You need to tell it which button to use:

response = br.submit(name='ctl00$QuickSearch1$CvrSearchButton')

Which works but raises a problem with robots.txt, an ethical dilemma.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top