任何人都可以帮我正确选择此表单吗?
试图抓取谷歌,我收到错误:mechanize._mechanize.FormNotFoundError: no form matching name 'q'
不寻常,因为我看过其他几个使用它的教程,并且: ps 我不打算通过请求来 SLAM google,只是希望使用自动选择器来不时查找学术引文 pdf。
<f GET http://www.google.com.tw/search application/x-www-form-urlencoded
<HiddenControl(ie=Big5) (readonly)>
<HiddenControl(hl=zh-TW) (readonly)>
<HiddenControl(source=hp) (readonly)>
<TextControl(q=)>
<SubmitControl(btnG=Google ?j?M) (readonly)>
<SubmitControl(btnI=?n???) (readonly)>
<HiddenControl(gbv=1) (readonly)>>
>>> quit()
import os, subprocess
import re
import mechanize
from bs4 import BeautifulSoup
#prepare mechanize
br = mechanize.Browser()
br.set_handle_robots(False)
br.set_handle_equiv(False)
br.addheaders = [('User-agent', 'Mozilla/5.0')]
br.open('http://www.google.com/')
br.select_form('q')
citation = ' www.stackoverflow.com '.strip()
#citation = GOOGLE_BASE + Citation
print citation
br.open('http://www.google.com/')
br.select_form('q')
br.form['q'] = citation
br.submit()
data = br.read()
soup = BeautifulSoup(data)
print soup