机械化没有看到一些隐藏的表单输入? [英] Mechanize does not see some hidden form inputs?
本文介绍了机械化没有看到一些隐藏的表单输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用Mechanize抓取此网页.表单元素如下所示:
I want to scrape this web page using Mechanize. The form element looks like this:
<form name="ctl00" method="post" action="PSearchResults.aspx?state=ME&rp=" id="ctl00">
<div>
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="verylongstring" /> </div>
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgKb7POZAwK4v7ffCOmari00yJft/iuZBMdOH/zh9TDI" />
</div>
</form>
我正在使用Mechanize打印出控件,但只能看到其中两个.如果我运行此命令:
I'm using Mechanize to print out the controls, but it can only see two of them. If I run this:
br.select_form(name='ctl00')
br.form.set_all_readonly(False) # allow changing the .value of all controls
for control in br.form.controls:
if not control.name:
print " - (type) =", (control.type)
continue
print " - (name, type, value) =", (control.name, control.type, br[control.name])
所有打印的是这样的:
- (name, type, value) = ('__VIEWSTATE', 'hidden', '/wEPDwUGNDQ5NTMwD2QWAgIBD2QWAgIHD2QWCgIBDw8WAh4E...more
- (name, type, value) = ('__EVENTVALIDATION', 'hidden', '/wEWAgKb7POZAwK4v7ffCOmari00yJft/iuZBMdOH/zh9TDI')
为什么不能机械化查看" __EVENTTARGET和__EVENTARGUMENT字段?
Why can't Mechanize 'see' the __EVENTTARGET and __EVENTARGUMENT fields?
推荐答案
该站点正在检查用户代理并提供另一个页面进行机械化
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
这是一个链接,其中显示了如何使用机械化设置User-Agent
Here is a link showing how to set the User-Agent with mechanize
这篇关于机械化没有看到一些隐藏的表单输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文