如何登录到Google然后得到输出html?

2024-03-28 18:36:06 发布

您现在位置:Python中文网/ 问答频道 /正文

如何登录到Google,然后使用Python脚本获得输出html?在

我不想使用Selenium,只是一系列GET/POST请求。在

当我输入电子邮件时,我曾使用Burp Suite拦截POST请求。我不理解所有这些参数和字段,得到了405错误。在

我试过:

import requests
URL = "https://accounts.google.com/ServiceLogin/identifier?flowName=GlifWebSignIn&flowEntry=AddSession"

r = requests.post(url = URL, data ={'f.req':'my_email'})

output = r.text

张贴标题 Post Headers

发布参数 Post Params

我需要做一个POST请求来登录,然后再做一个GET请求来获取下一个页面。在


Tags: httpsimport脚本url参数gethtmlselenium
1条回答
网友
1楼 · 发布于 2024-03-28 18:36:06

这是用于登录gmail帐户的python脚本

import requests

url = "https://accounts.google.com/signin/v2/identifier"

querystring = {"service":"mail","passive":"true","rm":"false","continue":"https://mail.google.com/mail/","ss":"1","scc":"1","ltmpl":"default","ltmplcache":"2","emr":"1","osid":"1","flowName":"GlifWebSignIn","flowEntry":"ServiceLogin"}

headers = {
    'authorization': "Basic **base64 format of your email and password**",
    'cache-control': "no-cache",
    'postman-token': "0a86044e-5956-9b9c-616b-6d9f22f1560c"
    }

response = requests.request("POST", url, headers=headers, params=querystring)

print(response.text)

例如,输入base64解码格式的电子邮件和密码 使用此格式

^{pr2}$

相关问题 更多 >