Objective: I am trying to pull data from the Detailed forecast section on this weather forecast website. Then I am trying to put that data in a tabular data frame using pandas
Question: I get an error in the last line - could I get some advice, please?
This is my code thus far:
import csv
import requests
from bs4 import BeautifulSoup
from IPython.display import HTML
!pip install BS4
!pip install Requests
!pip install lxml
page = requests.get("http://forecast.weather.gov/MapClick.php?lat=37.7772&lon
soup = BeautifulSoup(page.content, 'html.parser')
seven_day = soup.find(id="detailed-forecast")
forecast_items = seven_day.find_all(class_="panel-body")
tonight = forecast_items[0]
print(tonight.prettify())
period = tonight.find(class_="col-sm-2 forecast-label").get_text()
short_desc = tonight.find(class_="col-sm-10 forecast-text").get_text()
print(period)
print(short_desc)
period_tags = seven_day.select(".panel-body.col-sm-10 forecast-text")
periods = [pt.get_text() for pt in period_tags]
short_descs = [sd.get_text() for sd in seven_day.select(".panel-body .col-smtemps
= [t.get_text() for t in seven_day.select(".tombstone-container .temp")
import pandas as pd
weather = pd.DataFrame({
"period": period,
"short_desc": desc,
})
weather
Aucun commentaire:
Enregistrer un commentaire