Skip to content

Instantly share code, notes, and snippets.

@mehdimehdi
Created June 12, 2012 01:28
Show Gist options
  • Save mehdimehdi/2913851 to your computer and use it in GitHub Desktop.
Save mehdimehdi/2913851 to your computer and use it in GitHub Desktop.
import urllib
import urllib2
import simplejson
import re
import time
from urlparse import urlparse
RESOURCE_URL = 'https://graph.facebook.com/'
params = {'access_token':'SOMEHTING'}
values = urllib.urlencode(params)
req = urllib2.Request("%sme/friends?%s" % (RESOURCE_URL,values), None)
excluded_hostname = ['flickr.com', 'soundcloud.com' 'www.couchsurfing.org', 'twitter.com', 'www.linkedin.com', 'plus.google.com', 'www.behance.net', 'flavors.me', 'www.youtube.com', 'picasaweb.google.com', 'meebo.com', 'yelp.com', 'facebook.com', 'viadeo.com','www.myspace.com','www.last.fm','www.facebook.com']
response = urllib2.urlopen(req)
content = response.read()
json_content = simplejson.loads(content)
for friend in json_content['data']:
time.sleep(2)
req = urllib2.Request("%s%s?%s" % (RESOURCE_URL,friend['id'],values), None)
try:
response = urllib2.urlopen(req)
except urllib2.HTTPError:
print 'error for %s' % (friend['name'])
continue
content = response.read()
boom = simplejson.loads(content)
if 'website' in boom:
try:
biim = re.findall(r'(https?://\S+)', boom['website'])
except AttributeError:
continue
for b in biim:
parsed = urlparse(b)
hostname = parsed.hostname
if hostname not in excluded_hostname:
print hostname
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment