Guest User

Untitled

a guest
Sep 25th, 2018
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. https://www.facebook.com/search/pages/?q=Los%20Angeles%20remodeling
  2. https://www.facebook.com/search/pages/?q=Boston%20remodeling
  3. https://www.facebook.com/search/pages/?q=Chicago%20remodeling
  4.  
  5.  
  6.  
  7. import time
  8. from selenium import webdriver
  9. from bs4 import BeautifulSoup as bs
  10. import csv
  11. import requests
  12. from selenium.webdriver.support.ui import WebDriverWait
  13.  
  14.  
  15.  
  16. driver = webdriver.Firefox()
  17.  
  18. _browser_profile = webdriver.FirefoxProfile()
  19. _browser_profile.set_preference("dom.webnotifications.enabled", False)
  20. webdriver.Firefox(firefox_profile=_browser_profile)
  21.  
  22. driver.get('https://www.facebook.com')
  23. username = driver.find_element_by_id("email")
  24. password = driver.find_element_by_id("pass")
  25. username.send_keys("robkrouse@gmail.com")
  26. password.send_keys("Single3#")
  27. driver.find_element_by_id('loginbutton').click()
  28. time.sleep(2)
  29.  
  30. with open('fb_urls.csv') as f_input, open('fb_profile_urls.csv', 'w', newline='') as f_output:
  31. csv_input = csv.reader(f_input)
  32. csv_output = csv.writer(f_output)
  33. for url in csv_input:
  34. driver.get(url[0])
  35. WebDriverWait(driver, 10)
  36. lenOfPage = driver.execute_script("window.scrollTo(0, document.body.scrollHeight);var lenOfPage=document.body.scrollHeight;return lenOfPage;")
  37. match=False
  38. while(match==False):
  39. lastCount = lenOfPage
  40. time.sleep(1)
  41. lenOfPage = driver.execute_script("window.scrollTo(0, document.body.scrollHeight);var lenOfPage=document.body.scrollHeight;return lenOfPage;")
  42. if lastCount==lenOfPage:
  43. match=True
  44. soup = bs(driver.find_elements_by_class_name('_32mo'), "lxml")
  45. csv_output.writerow(soup)
Add Comment
Please, Sign In to add comment