Python 如何使mechanize在本页的表单中不失败?
上述代码导致:Python 如何使mechanize在本页的表单中不失败?,python,automation,screen-scraping,mechanize,Python,Automation,Screen Scraping,Mechanize,上述代码导致: import mechanize url = 'http://steamcommunity.com' br=mechanize.Browser(factory=mechanize.RobustFactory()) br.open(url) print br.request print br.form for each in br.forms(): print each print 您是否提到该网站正在重定向到https(ssl)服务器 那么,尝试设置一个新
import mechanize
url = 'http://steamcommunity.com'
br=mechanize.Browser(factory=mechanize.RobustFactory())
br.open(url)
print br.request
print br.form
for each in br.forms():
print each
print
您是否提到该网站正在重定向到https(ssl)服务器 那么,尝试设置一个新的HTTPS处理程序,如下所示:
url = 'https://steamcommunity.com'
hh = mechanize.HTTPSHandler() # you might want HTTPSHandler, too
hh.set_http_debuglevel(1)
opener = mechanize.build_opener(hh)
response = opener.open(url)
contents = response.readlines()
print contents
使用这个秘密,我相信这对你有用;)
我确实忘了添加那个信息,谢谢。不幸的是,添加您提到的行并没有改变任何事情。对我来说不起作用,我仍然得到
mechanize.\u form.ParseError:nested FORMs
。我试过使用mechanize 0.2.5
以及stock Debianpython mechanize 0.1.11
在br.forms()中是否必须像这样首先检查元素:打印这可以帮助您首先检查表单元素
url = 'https://steamcommunity.com'
hh = mechanize.HTTPSHandler() # you might want HTTPSHandler, too
hh.set_http_debuglevel(1)
opener = mechanize.build_opener(hh)
response = opener.open(url)
contents = response.readlines()
print contents
mechanize.HTTPSHandler()
br = mechanize.Browser(factory=mechanize.DefaultFactory(i_want_broken_xhtml_support=True))