Facebook 登录 -Python 3 请求模块 [英] Facebook login -Python 3 Requests module

查看:34
本文介绍了Facebook 登录 -Python 3 请求模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么这个脚本仍然把我带到主页(未登录)?想象一下电子邮件和通行证都很好

Why does this script still bring me to the main page (not logged in)? Imagine the email and pass were good

import requests
par = {'email':'addddd','Pass':'ggdddssd'}
r = requests.post('https://www.facebook.com',data=par)
print (r.text)

甚至尝试使用 youtube 上的搜索栏进行搜索:

or even trying trying to search with the search bar on youtube:

<input id="masthead-search-term" name="search_query" value="" type="text" tabindex="1"title="Rechercher">

import requests
par = {'search_query':'good_songs_on_youtube'}
r = requests.post('https://www.youtube.com',data=par)
print (r.text)

不进行任何搜索...有什么想法吗?

doesn't make any search... any ideas why?

推荐答案

您将无法像这样登录有两个原因:

You won't be able to login like this for two reasons:

  1. 当您发布 HTML 表单时 - 您应该使用表单的操作"作为 url.例如:

<小时>

import requests
url = 'https://www.facebook.com/login.php?login_attempt=1' #the form's action url
par = {"email": "********", "password": "********"} # the forms parameters
r = requests.post(url, data=par)
print (r.content) # you can't use r.text because of encoding

<小时>

  1. 在您的情况下,这也不够好,因为 FB 需要 cookie,您可能可以通过编程摆脱它,但这并不容易/直截了当.

那么,您如何登录(以编程方式)到 FB 并发布查询?您可以安装和使用 他们的SDK,还有这个等开源项目使用 FB API 并支持 oauth.

So, how can you login (programmatically) to FB and post queries ? You can install and use their SDK, and there are also open source projects such as this one that uses FB API and supports oauth as well.

你必须去https://developers.facebook.com/tools/explorer/ 并获取您的 API 令牌,以便将其与 oauth 身份验证一起使用.

You will have to go to https://developers.facebook.com/tools/explorer/ and get your API token in order to use it with the oauth authentication.

这篇关于Facebook 登录 -Python 3 请求模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆