Created
August 20, 2012 22:20
-
-
Save jorgebastida/3408554 to your computer and use it in GitHub Desktop.
grequests facebook company scrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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