This goes to a URL from the CSV file , then scrolls down. I'm trying to grab the company URLs off of the page. I can't seem to get it to work. Now if I use just one stand alone URL without pulling it from the CSV, it will print to powershell. Still can't get it to write to CSV.
Here is a couple of URLs that I'm working with:
https://www.facebook.com/search/pages/?q=Los%20Angeles%20remodeling
https://www.facebook.com/search/pages/?q=Boston%20remodeling
The thought I had was that it has to be a loop within a loop. Or, it could be if
, elif
. I'm not really sure at this point. Any and all suggestions would be appreciated.
import time
from selenium import webdriver
from bs4 import BeautifulSoup as bs
import csv
import requests
from selenium.webdriver.support.ui import WebDriverWait
driver = webdriver.Chrome()
elems = driver.find_elements_by_class_name('_32mo')
chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications" : 2}
chrome_options.add_experimental_option("prefs",prefs)
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get('https://www.facebook.com')
username = driver.find_element_by_id("email")
password = driver.find_element_by_id("pass")
username.send_keys("*****")
password.send_keys("******")
driver.find_element_by_id('loginbutton').click()
time.sleep(2)
with open('fb_urls.csv') as f_input, open('fb_profile_urls.csv', 'w', newline=) as f_output:
csv_input = csv.reader(f_input)
csv_output = csv.writer(f_output)
for url in csv_input:
driver.get(url[0])
time.sleep(5)
lenOfPage = driver.execute_script("window.scrollTo(0, document.body.scrollHeight);var lenOfPage=document.body.scrollHeight;return lenOfPage;")
match=False
while(match==False):
lastCount = lenOfPage
time.sleep(1)
lenOfPage = driver.execute_script("window.scrollTo(0, document.body.scrollHeight);var lenOfPage=document.body.scrollHeight;return lenOfPage;")
if lastCount==lenOfPage:
match=True
for elem in elems:
csv_output.(driver.find_elements_by_tag_name('href'))