1234567891011121314151617181920212223242526272829303132333435363738# -*- coding: utf-8 -*-"""@Time : 2022/12/12 18:52@Author : daokunn@File :九江天气.py@IDE :PyCharm@Motto: Don’t cry over spilt milk.功能: 查询九江当天的天气"""import requestsfrom bs4 import BeautifulSoupdef jj_weather(): # print('九江') res = requests.get('http://www.weather.com.cn/weather/101010100.shtml') res.encoding = 'utf-8' html = res.text soup = BeautifulSoup(html,'html.parser')#解析文档 weathers = soup.find(id="7d",class_="c7d").find('ul',class_="t clearfix").find_all('li') result = {} for weather in weathers: weather_date = weather.find('h1') weather_wea = (weather.find('p',class_='wea')) weather_tem = (weather.find('p',class_= 'tem')) result['日期'] = weather_date.text result['天气'] = weather_wea.text result['温度'] = weather_tem.text[1:-1] print(result) # print('日期:',result['日期']) return resultprint(jj_weather())