Skip to content Skip to sidebar Skip to footer

Facebook Login -python 3 Requests Module

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.

Solution 1:

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

  1. When you post an HTML form - you should use the form's "action" as the url. For example:

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. In your case, this is also not good enough cause FB requires cookies, you might be able to program your way out of it, but it won't be easy/straight-forward.

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.

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.

Solution 2:

For youtube, you should use "GET" request instead of post to get the valid response. I've given a demo using your search query "good_songs" and showed how to fetch the results:

import requests
from lxml importhtmlurl='https://www.youtube.com/results?search_query='
search = 'good_songs'

response = requests.get(url + search).texttree= html.fromstring(response)
for item in tree.xpath("//a[contains(concat(' ', @class, ' '), ' yt-uix-tile-link ')]/text()"):
    print (item)

Post a Comment for "Facebook Login -python 3 Requests Module"