我正在尝试创建一个使用 mechanize 将数据提交到 Web 表单的 Python 脚本。
这就是我目前所拥有的
import mechanize
username = <my_username>
password = <my_password>
url = <my_url>
print "opening browser"
br = mechanize.Browser()
print "opening url...please wait"
br.open(url)
print br.title()
print "selecting form"
br.select_form(name='Login')
br['UserID'] = username
br['PassPhrase'] = password
print "submitting form"
br.submit()
我现在不知道该做什么。 br
现在是否包含提交表单后出现的下一个网页?有没有办法可以打印 br
中的 html
来检查其中的网页? (我不能使用 print br.title()
因为两个页面都有相同的标题)
最佳答案
最后试试这个:
response = br.submit()
pageSource=response.read()
pageSource 应该为您提供登录后页面的 html 源代码。
关于python - 使用 python mechanize 登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40827885/