Skip to content

Instantly share code, notes, and snippets.

@jorgebastida
Created August 20, 2012 22:20
Show Gist options
  • Select an option

  • Save jorgebastida/3408554 to your computer and use it in GitHub Desktop.

Select an option

Save jorgebastida/3408554 to your computer and use it in GitHub Desktop.
grequests facebook company scrapper
import grequests
TOKEN = '<TOKEN>'
ENDPOINT = ('https://api.facebook.com/method/fql.query?query=SELECT+'
'page_url,fan_count,location,products,description,'
'company_overview,general_info,website,founded,'
'mission+FROM+page+WHERE+%(query)s&'
'access_token=%(token)s&format=json')
QUERY_USERNAME = 'username="%s"'
QUERY_NAME = 'name="%s"'
COMPANIES = """AAA
BBB
CCC
DDD
EEE""".split('\n')
def urls_generator():
for name in COMPANIES:
name = name.strip()
name = name.replace('Limited', '').replace('Ltd', '').replace(' ', '%20')
yield ENDPOINT % {'query': QUERY_NAME % name, 'token': TOKEN}
yield ENDPOINT % {'query': QUERY_USERNAME % name, 'token': TOKEN}
rs = (grequests.get(u) for u in urls_generator())
for response in grequests.imap(rs, size=10):
if not isinstance(response.json, dict) and response.json:
print response.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment