Python 2.7 在Python 2.7.5上使用Mechanize登录Bing
我正在尝试使用Python 2.7.5和创建一个程序,将我登录到我的Microsoft帐户。首先,我创建了这个程序来打印这个网页上表单的名称,以便在以后的代码中引用它们。我当前的代码如下(很抱歉URL太长):Python 2.7 在Python 2.7.5上使用Mechanize登录Bing,python-2.7,automation,mechanize,bing,Python 2.7,Automation,Mechanize,Bing,我正在尝试使用Python 2.7.5和创建一个程序,将我登录到我的Microsoft帐户。首先,我创建了这个程序来打印这个网页上表单的名称,以便在以后的代码中引用它们。我当前的代码如下(很抱歉URL太长): 导入机械化 br=mechanize.Browser() br.设置手柄机器人(错误) br.addheaders=[('User-agent','Firefox')] br.打开(“https://login.live.com/ppsecure/post.srf?wa=wsignin1.
导入机械化
br=mechanize.Browser()
br.设置手柄机器人(错误)
br.addheaders=[('User-agent','Firefox')]
br.打开(“https://login.live.com/ppsecure/post.srf?wa=wsignin1.0&rpsnv=11&ct=1375231095&rver=6.0.5286.0&wp=MBI&wreply=http:如果你试图阅读你收到的HTML,你会发现网页需要javascript
例如:
import mechanize
br = mechanize.Browser()
br.set_handle_robots(False)
br.addheaders = [('User-agent','Firefox')]
page = br.open("https://login.live.com/ppsecure/post.srf?wa=wsignin1.0&rpsnv=11&ct=1375231095&rver=6.0.5286.0&wp=MBI&wreply=http:<%2F%2Fwww.bing.com%2FPassport.aspx%3Frequrl%3Dhttp%253a%252f%252fwww.bing.com%252f&lc=1033&id=264960&bk=1375231423")
print page.read()
print(br.title)
forms_printed = 0
for form in br.forms():
print form
forms_printed += 1
if forms_printed == 0:
print "No forms to print!"
看看吧
import mechanize
br = mechanize.Browser()
br.set_handle_robots(False)
br.addheaders = [('User-agent','Firefox')]
page = br.open("https://login.live.com/ppsecure/post.srf?wa=wsignin1.0&rpsnv=11&ct=1375231095&rver=6.0.5286.0&wp=MBI&wreply=http:<%2F%2Fwww.bing.com%2FPassport.aspx%3Frequrl%3Dhttp%253a%252f%252fwww.bing.com%252f&lc=1033&id=264960&bk=1375231423")
print page.read()
print(br.title)
forms_printed = 0
for form in br.forms():
print form
forms_printed += 1
if forms_printed == 0:
print "No forms to print!"
Microsoft account
JavaScript required to sign in
Microsoft account requires JavaScript to sign in. This web browser either does not support JavaScript, or scripts are being blocked.
To find out whether your browser supports JavaScript, or to allow scripts, see the browser's online help.