Mechanize does not see some hidden form inputs?

一世执手 提交于 2019-12-01 06:42:11

The site is checking the useragent and serving a different page to mechanize

specifying this as the useragent seems to work ok

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6

Here is a link showing how to set the User-Agent with mechanize

As a follow up, I had the same problem using mechanize (python) and I tried defining the UserAgent to

br.addheaders = [('User-agent', 'Mozilla/5.0 (Windows NT 5.2; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.47 Safari/536.11')]

as recommended by the site: http://stockrt.github.com/p/emulating-a-browser-in-python-with-mechanize/

However, this did not work so I opted to included the missing forms elements using the following code:

br.select_form(name='form')
br.form.set_all_readonly(False) # allow changing the .value of all controls
br.form.new_control('text','__EVENTARGUMENT',{'value':''})
br.form.new_control('text','__EVENTTARGET',{'value':''})
br.form.fixup()
br["__EVENTTARGET"] = 'lbSearch'
br["__EVENTARGUMENT"] = ''
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!