使用Python 2.7.x和Mechanize,我试图获取Bing的表单名称并进行搜索:
import mechanize
AGENT = mechanize.Browser()
BING = "http://www.bing.com"
def bing_search(query):
AGENT.open(BING)
for form in AGENT.forms():
print form
AGENT.select_form(name="q")
AGENT.form["q"] = query
data = AGENT.submit()
输出如下:
C:\Users\z-perkins-thomas\Documents\bin\python\some-type-of-scanner>python querymine.py
<GET http://www.bing.com/search application/x-www-form-urlencoded
<TextControl(q=)>
<SubmitControl(go=) (readonly)>
<HiddenControl(qs=ds) (readonly)>
<HiddenControl(form=QBLH) (readonly)>>
Traceback (most recent call last):
File "querymine.py", line 4, in <module>
bing_search("test")
File "C:\Users\z-perkins-thomas\Documents\bin\python\some-type-of-scanner\bin\harvest\search_engines\__init__.py", line
55, in bing_search
AGENT.select_form(name="q")
File "C:\Python27\lib\site-packages\mechanize\_mechanize.py", line 524, in select_form
raise FormNotFoundError("no form matching "+description)
mechanize._mechanize.FormNotFoundError: no form matching name 'q'
C:\Users\z-perkins-thomas\Documents\bin\python\some-type-of-scanner>
正如您所看到的那样,列出了表单名称,但是尝试任何列出的表单名称都不起作用并输出同样的问题,我在这里做错了什么?
答案 0 :(得分:0)
您似乎正在尝试选择名称为List<Integer> integers = new ArrayList<Integer>();
while (!(new HashSet<Integer>(integers).size() == 1 && integers.get(0).intValue() == -1)){
....
}
且bing.com上不存在的表单。但是,有一个带有该名称的输入字段。
您应该像这样使用它:
q