Facebook data without Opengraph

47 views
Skip to first unread message

Gabriela Campedelli

unread,
Oct 10, 2017, 8:01:34 PM10/10/17
to ScraperWiki
Hello:

As you may know, Facebook has Opengraph API with JSON output and token access, but some useful data are not available using opengraph and nor it is in Json. 
I have search data that I would like to get using Scraperwiki, now Quickcode. 
The snippet I´m using is bellow but it only gets the page network, which means others pages that the page I´m scraping liked. 
But I want to get users IDs that liked the page and that is deprecated in Opengraph. So this information is only available in search.


The major problem is that account has to be logged in Facebook to access this page as a regular user. I can,, of course, scrape the code after login using a js script in Chrome console, but it would be a great idea to do it automatically using Scraperwiki. Does anyone have an idea on how to do that? I promise to share the js I´m using in Chrome console. 
Here is the snippet for Opengraph:

#!/usr/bin/env python

import scraperwiki
import json

html = scraperwiki.scrape("https://graph.facebook.com/v2.7/{page-id}/likes?access_token={value - you can replace with your access token here}")
print  html

# Saving data:
for i in html:
    html={'data'}
    data=['i']
    print i
#scraperwiki.sql.save(unique_keys, data)

Thank you so much for your help
Gabriela

Gabriela Campedelli

unread,
Oct 10, 2017, 9:49:32 PM10/10/17
to ScraperWiki
I found a code that is able to login but I have to understand more about cookies because it is giving me an error. I´ve commented the line, error has gone away, I´ve logged and Facebook notified me that I have a login from Dublin after blocking my account for security reasons. So, if anyone can help me to improve this code, I would be very happy for that. Is it better to use Mechanize? How do you feel about it? 

#!/usr/bin/env python

import requests

USERNAME = 'your email'
PASSWORD = 'your password'

def login(session, email, password):
  
    # Attempt to login to Facebook
        'email': email,
        'pass': password
    }, allow_redirects=False)

    assert response.status_code == 302
    assert 'c_user' in response.cookies
    return response.cookies

if __name__ == "__main__":

    session = requests.session()
    #cookies = login(session, USERNAME, PASSWORD)
    response = session.get(PROTECTED_URL, 
allow_redirects=False)
    #assert response.text.find('Home') != -1
Reply all
Reply to author
Forward
0 new messages