from urllib.request import urlopen
from bs4 import BeautifulSoup
from xpinyin import Pinyin
prov = input("请输入省份:")
city = input("请输入城市:")
pin = Pinyin()
prov_pin = pin.get_pinyin(prov,'')
city_pin = pin.get_pinyin(city,'')
moji_url = "https://tianqi.moji.com/weather/china/"
moji_url = moji_url + prov_pin + '/' + city_pin
url = urlopen(moji_url)
soup = BeautifulSoup(url, 'html.parser')
alert = soup.find('div', class_="wea_alert clearfix").em
print(prov + "省" + city+ "市天气:")
print("空气质量:" + alert.string)
weather = soup.find('div', class_="wea_weather clearfix")
print("当前温度:" + weather.em.string + "℃")
print("天气:" + weather.b.string)
python爬取墨迹天气
最新推荐文章于 2021-06-04 18:21:45 发布