-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
36 lines (29 loc) · 1.2 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import pandas as pd
import requests
from bs4 import BeautifulSoup
try :
# past here your link
page = requests.get('https://forecast.weather.gov/MapClick.php?lat=34.05349000000007&lon=-118.24531999999999')
soup = BeautifulSoup(page.content, 'html.parser')
week= soup.find(id="seven-day-forecast-body")
items = week.find_all(class_="tombstone-container")
#print(items[0])
print(items[0].find(class_="period-name").get_text())
print(items[0].find(class_="short-desc").get_text())
print(items[0].find(class_="temp").get_text())
period_names = [item.find(class_="period-name").get_text() for item in items]
#print(period_names)
short_descriptions = [item.find(class_="short-desc").get_text() for item in items]
#print(short_descriptions)
temperature = [item.find(class_="temp").get_text() for item in items]
#print(temperature)
wether_stuff = pd.DataFrame(
{'period': period_names,
'short_descriptions': short_descriptions,
'temperature': temperature,
}
)
print(wether_stuff)
wether_stuff.to_csv('first.csv')
except :
print("https://forecast.weather.gov \n \n go there select your location and past url.")