from bs4 import BeautifulSoup
import json, requests
import lxml.html
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36'}
form_data = {}
url = 'https://accounts.google.com/Login'
login = requests.get(url)
html = lxml.html.fromstring ( login.text )
data = html.xpath('//input[@type="hidden"]')
for x in data:
name = x.get('name')
value = x.get('value')
form_data[name] = value
form_data['Email'] = 'my email here'
form_data['Passwd'] = 'my password here'
print(form_data)
with requests.session() as s:
response = requests.post(url, data=form_data, headers=headers)
req = requests.get('https://mail.google.com/mail/u/0/#inbox')
print(req.text)
print ( 'inbakke' in req )
我尝试制作一个请求使用帖子登录的脚本。但它不起作用。当我在最后查看“req.text”html时。好像我还在提交你的passwd和电子邮件页面。 https://gyazo.com/2db56030077c2e9a73154de0ab9f801c - “req.text”
我发送的form_data如下:
{'_utf8': '☃', 'Email': 'MY EMAIL', 'SessionState': '', 'bgresponse': 'js_disabled', 'GALX': '0vyTLpgavJc', 'ProfileInformation': '', 'gxf': 'AFoagUXHK7rZNkBVVIUkhqVxSRX27RFOLg:1482790613384', 'Page': 'PasswordSeparationSignIn', 'Passwd': 'MY PASSOWRD'}
有些聪明人可以解释一下出了什么问题,以及我该如何解决它?