这是迄今为止我已经借了代码的伟大工程在Google.com上而不是在pastebin.com会喜欢上我为什么不能搜索pastebin.com一些输入搜索Pastbin.com与机械化
import re
from mechanize import Browser
br = Browser()
# Ignore robots.txt
br.set_handle_robots(False)
# user-agent that isn't a robot
br.addheaders = [('User-agent', 'Firefox')]
# Retrieve the web page
br.open("http://pastebin.com")
# Select the search box and search for 'foo'
br.select_form('f')
br.form[ 'q' ] = 'facebook'
# Get the search results
br.submit()
# Find the link
resp = None
for link in br.links():
siteMatch = re.compile('www.facebook.com').search(link.url)
if siteMatch:
resp = br.follow_link(link)
break
# Print the site
content = resp.get_data()
print content
这是什么意思,你不能搜索?任何错误? – alecxe 2014-09-02 19:41:41
select_form中的文件“build/bdist.macosx-10.3-fat/egg/mechanize/_mechanize.py”,第524行,在select_form中 mechanize._mechanize.FormNotFoundError:没有表单匹配名称'f' – 2014-09-02 19:42:37
完成任何基本的调试, pastebine发送你的脚本?你只是假设什么都不会出错。 – 2014-09-02 19:42:41