MaLittlePwny

Untitled

Feb 6th, 2015
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. from selenium import webdriver
  2. from selenium.webdriver.common.keys import Keys
  3. import time
  4. from bs4 import BeautifulSoup
  5. import re
  6.  
  7. usr = "*************"
  8. pwd = "*************"
  9. fbid = "***startId***"
  10.  
  11. FRIEND_DATA = {}
  12.  
  13. profile = webdriver.FirefoxProfile("Profiles/test1")
  14. driver = webdriver.Firefox(firefox_profile=profile)
  15.  
  16. def getFriendSource(fbid):
  17.  
  18.     driver.get("https://www.facebook.com/profile.php?id=%s&sk=friends"% fbid)
  19.     for i in range(5):
  20.         #driver.execute_script("window.scrollTo(0,document.body.scrollHeight)")
  21.         time.sleep(0.1)
  22.     soup = BeautifulSoup(driver.page_source)
  23.     friends = []
  24.     for link in soup.find_all('a'):
  25.         href = str(link.get('data-hovercard'))
  26.         if "hovercard/user.php?id=" in href:
  27.             href = href[28:-59]
  28.             if href not in friends:
  29.                 friends.append(href)
  30.     FRIEND_DATA[fbid] = friends
  31.  
  32.     return friends
  33.  
  34. for friend in getFriendSource(fbid):
  35.     getFriendSource(friend)
  36. driver.close()
  37.  
  38. print(FRIEND_DATA)
Advertisement
Add Comment
Please, Sign In to add comment