I made this little script as I'm learning to scrape with bs4 and selenium and I want to collect periodic date of weather into a csv file but I am quite new and I don't know where to begin.
Can someone point me in the right direction on to how to make this run every date and append data? For now, I run and it just makes the header and the second row.
from bs4 import BeautifulSoup from selenium import webdriver from selenium.webdriver.common.by import By from csv import writer
url = 'https://weather.com/es-US/tiempo/10dias/l/468124beb45cd6817ec6a1da2675f104fede76a75ba7ce08c9ae21606ac208b5'
driver = webdriver.Chrome('/Users/thras/Desktop/Chromedriver/chromedriver')
driver.get(url)
source = driver.page_source
soup = BeautifulSoup(source, 'html.parser')
degrees = soup.find('span', class_="DailyContent--temp--3d4dn").text
humidity = soup.find('span', class_="Wind--windWrapper--3aqXJ DailyContent--value--37sk2").text
wind = soup.find('span', class_="DailyContent--temp--3d4dn").text
date = soup.find('span', class_="DailyContent--daypartDate--2A3Wi").text
info = [degrees, humidity, wind, date]
with open('weather.csv', 'w', encoding='utf8', newline='') as f:
mywriter = writer(f)
header = ('Degrees', 'Humidity', 'Wind', 'Date')
mywriter.writerow(header)
mywriter.writerow([degrees, humidity, wind, date])
driver.quit()