获取某一个城市的天气情况

1、代码

import requests
from bs4 import BeautifulSoup

url = 'http://www.weather.com.cn/weather/101200101.shtml'
response = requests.get(url)
soup = BeautifulSoup(response.content, 'html.parser')

temperature = soup.find(class_='tem').text.strip()
weather = soup.find(class_='wea').text.strip()
print(f'武汉当前天气:{
      
      weather},温度:{
      
      temperature}')

2、效果

在这里插入图片描述

3、改进

后续做成可视化。

猜你喜欢

转载自blog.csdn.net/qq_45194089/article/details/129205937
今日推荐