Python3如何使用请求登录Facebook? [英] Python3 How would I log in Facebook using requests
问题描述
< input type =textclass =inputtextname =emailid =emailvalue =tabindex =1>
是电子邮件箱
< input type =passwordclass =inputtextname =passid =passtabindex = 2>
是密码框
< input value =Connexiontabindex =4 type =submitid =u_0_v>
是提交按钮
现在...我有这个脚本运行,但我仍然无法设置登录(我得到相同的登录页面:facebook.com)
<input value="Connexion" tabindex="4" type="submit" id="u_0_v">
is the submit button
Now... I have this script running but I still can't manage to login ( I get to the same login page: facebook.com)
import requests
from bs4 import BeautifulSoup
body = {'email':'xxxx@hotmail.com','pass':'xxxxx',}
con = requests.post('https://www.facebook.com', data=body)
s = BeautifulSoup(con.content)
print (s)
我必须通过正文{}中的提交按钮。我以为我应该包括它,但没有提交按钮的名称,所以我不知道如何将它包含在身体{}中。感谢您的帮助
Do I have to pass in the 'submit button' in the body{}. I thought I should include it but there is no name for the submit button so I don't know how to include it in the body{}. Thanks for the help
推荐答案
您始终需要注意任何其他(隐藏)字段,这些字段是沿凭证发送的,可能需要任何服务器处理。
You always need to pay attention to any additional (hidden) fields, that are sent along credentials, and might be needed for any server processing.
您的示例是runescape.com的情况。当您使用浏览器截取数据时,通常会随表单一起发送,您可以按以下方式修改脚本:
That is the case for your example with runescape.com. When you use your browser to intercept data, that is normally being sent along with the form, you can modify the script in this manner:
import requests
from bs4 import BeautifulSoup
body = {'username':'xxxx@hotmail.com','password':'xxxxx','submit':'Login','mod':'www','dest':'community'}
con = requests.post('https://secure.runescape.com/m=weblogin/login.ws', data=body)
s = BeautifulSoup(con.content)
print(s)
你可以看到 mod
和 dest
需要参数才能使服务器处理功能。至于提交按钮,很少检查,但总是比较安全的(就像我在这个例子中一样)。
You can see mod
and dest
parameters were needed to make the server processing function. As for the submit button, it is rarely checked for, but it is always safer to include it as well (as I did in this example).
结果不是404,但是登录将失败,因为有验证码是为了防止自动登录。
The result is not 404 anymore, but the login will nevertheless fail, as there is Captcha in place to prevent automatic login.
至于Facebook,有很多复杂的补充领域,将需要大量的逆向工程来完成。我强烈建议您考虑使用官方Facebook Graph API( https://developers.facebook.com/ docs / graph-api ),如果可以完成你所需要的。
As for Facebook, there are a lot of complicated supplementary fields, that would require a lot of reverse engineering to be done. I would strongly suggest to consider using the official Facebook Graph API (https://developers.facebook.com/docs/graph-api) if possible to accomplish what you need.
这篇关于Python3如何使用请求登录Facebook?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!