…此外,我登录了fiddler打开的网站,所以我可以看到发布的内容是为了尝试更好地理解这个过程,我将该字符串存储在’actual_POST’下仅供参考.
s = requests.Session()url = "https://roosterteeth.com/login"payload = {'username': 'password','password': 'password','_token': 'GCZLoBNyjFrN2SReFjEydkN6qx6NT5hU8jVfyZol'}actual_POST = '_token=GCZLoBNyjFrN2SReFjEydkN6qx6NT5hU8jVfyZol&username=username&password=password&redirectTo=http%3A%2F%2Froosterteeth.com%2F'with s as j: b = s.post(url,data=payload,headers={'User-Agent': 'Mozilla/5.0'}) r = s.get('http://roosterteeth.com/episode/rt-sponsor-cut-season-2-sponsor-play-alIEn-isolation-dlc') print(r.text)解决方法 您不能使用从浏览器中提取的_token,您需要发出请求并从响应中解析_token然后在帖子中使用它:
import requestsfrom bs4 import BeautifulSoupurl = "https://roosterteeth.com/login"payload = {'username': 'dyour_user','password': 'your_pass',"redirectTo":"http://roosterteeth.com/"}headers= {'User-Agent': 'Mozilla/5.0 (X11; linux x86_64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/50.0.2661.75 Safari/537.36'}with requests.Session() as s: r = s.get(url) payload["_token"] = BeautifulSoup(r.text).select_one("input[name=_token]")["value"] b = s.post(url,headers=headers,allow_redirects=1) print(BeautifulSoup(b.text,"lxml").select("p.username"))
如果我们使用登录详细信息运行上面的代码,您可以看到我们成功:
In [21]: url = "https://roosterteeth.com/login"In [22]: payload = {'username': 'xxxxx','password': 'xxxxx',....: ....: "redirectTo": "http://roosterteeth.com/"}In [23]: headers = { ....: 'User-Agent': 'Mozilla/5.0 (X11; linux x86_64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/50.0.2661.75 Safari/537.36'}In [24]: with requests.Session() as s: ....: r = s.get(url) ....: payload["_token"] = BeautifulSoup(r.text,"lxml").select_one("input[name=_token]")["value"] ....: b = s.post(url,allow_redirects=1) ....: print(BeautifulSoup(b.text,"lxml").select("p.username")) ....: [<p ><a href="JavaScript:voID"> xxxxx <i ></i></a></p>]总结
以上是内存溢出为你收集整理的需要帮助搞清楚如何在python中发送POST登录信息全部内容,希望文章能够帮你解决需要帮助搞清楚如何在python中发送POST登录信息所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)