基于用户输入date/tim的大气数据Web抓取

2024-04-28 02:19:38 发布

您现在位置:Python中文网/ 问答频道 /正文

尝试根据用户输入的日期/时间打印大气数据。用于附加URL的日期输入。然后用户输入“time”,将BS4指向相应的行,然后存储每列的数据。例如,如果weather\u时间变量介于3:00-3:59之间,则输出将是表中突出显示的区域,并存储为唯一变量

enter image description here

from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup

print('What is the date (format 2018-09-18)?')
weather_date = input()
print('What time are you looking for?')
weather_time = input()

#connect to url
weather_url = 'https://www.wunderground.com/history/daily/KTTD/date/' + weather_date
uClient = uReq(weather_url)
weather_html = uClient.read()
uClient.close()
weather_soup = soup(weather_html, "html.parser")
weather = weather_soup.findAll......
###magic####

temperature =
dew_point =
humidity =
pressure =
condition =

print('The weather on', + weather_date, 'at time', weather_time, 'was')
print('Temperature', + temperature)
print('Dew Point', + dew_point)
print('Humidity', + humidity)
print('Pressure', + pressure)
print('Condition', + condition)

Tags: 数据用户fromimporturldatetimehtml