result = soup.findAll('div', {'class': 'tem'}) print("廊坊未来七天天气情况:") for i in range(7): date = soup.findAll('h1', {'class': 'date'})[i].string high_temp = result[i].find('span').string low_temp = result[i].find('i').string print(date + " 最高温度:" + high_temp + "℃ 最低温度:" + low_temp + "℃")

#BeautifulSoup解决爬取廊坊7日天气问题#导入BeautifulSoup库 #导入requests库 #导入re库 url = httpwwwweathercomcnweather101090601shtmlheaders = User-Agent Mozilla50 Windows NT 100; Win64; x64 AppleWebKit53736 KHTML like Geck

原文地址: https://www.cveoy.top/t/topic/eZAh 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录