Can anyone help me get this form selection correct?
Trying to get a crawl of google, I get the error: mechanize._mechanize.FormNotFoundError: no form matching name 'q'
Unusual, since I have seen several other tutorials using it, and: p.s. I don't plan to SLAM google with requests, just hope to use an automatic selector to take the effort out of finding academic citation pdfs from time to time.
<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