MLT

Python - Facebook Image to Profile Resolver

MLT
Nov 10th, 2013
600
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.31 KB | None | 0 0
  1. import sys
  2. from BeautifulSoup import BeautifulSoup
  3. import requests
  4.  
  5. def main(argv):
  6.         if len(argv) != 1:
  7.                 print "Usage: ./fbpic2id.py <Facebook Image URL>"
  8.                 exit(1)
  9.        
  10.         pic_url = argv[0]
  11.         album_url = "http://www.facebook.com/photo.php?fbid=" + pic_url.split('_')[1]
  12.         headers = {'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 6.1; nl; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13'}
  13.  
  14.         print "\nAlbum URL: " + album_url + "\n"
  15.        
  16.         req = requests.get(album_url, headers=headers)
  17.         soup = BeautifulSoup(req.text)
  18.        
  19.         # Grab the name of the owner that posted it.
  20.         # if the title isn't "Timeline Photos | Facebook" it must be a user
  21.         divTag = soup.findAll('title')
  22.         if divTag[0].text != "Timeline Photos | Facebook":
  23.                 if divTag[0].text.split('&')[0] == "Facebook":
  24.                         print "Can't find owner due to privacy settings"
  25.                         exit(1)
  26.                 print "Owner: " + divTag[0].text.split('&')[0]
  27.         else:
  28.                 divTag = soup.findAll('a')
  29.                 for tag in divTag:
  30.                         if tag.text.find("&#039;s Photos") != -1:
  31.                                 print "Owner (Page/Group): " + tag.text.split('&')[0]
  32.        
  33.         # If privacy settings are open, grab the link to the owner's page
  34.         divTag = soup.findAll('div', {'id':'fbPhotoPageAuthorPic'})
  35.         for tag in divTag:
  36.                 aTags = tag.findAll('a')
  37.                 for tag in aTags:
  38.                         if tag['href'] != '#':
  39.                                 print "Owner URL: "+tag['href']
  40.                         else:
  41.                                 print "Owner's URL Blocked by privacy settings"
  42.         # Grab all people tagged with weak privacy settings
  43.         divTag = soup.findAll('a', {'class':'taggee'})
  44.         print "\nTagged with profiles:"
  45.         for tag in divTag:
  46.                 print tag.text + " (" + tag['href'] + ")"
  47.        
  48.         # Grab the rest of the tagged people's names
  49.         print "\nTagged without profiles:"
  50.         divTag = soup.findAll('span', {'class':'taggee'})
  51.         for tag in divTag:
  52.                 print tag.text
  53.        
  54. if __name__ == "__main__":
  55.         main(sys.argv[1:])
Advertisement
Comments
  • Comment was deleted
Add Comment
Please, Sign In to add comment