目录
1. 爬取网站数据
在我们的Python中呢,使用爬虫可以轻松地获取网站的数据。可以使用urllib、requests、BeautifulSoup等库进行数据爬取和处理。以下是一段爬取天气信息的示例代码,欧蕾欧蕾欧蕾蕾:
import requests
from bs4 import BeautifulSoup
url = 'https://www.weather.com/zh-CN/weather/hourbyhour/l/China+Beijing+Beijing?canonicalCityId=4a7d9ad7fc0cbd7f58d22b2f3d5c3cd9eb520a9b49f797290e3a8ae30e23f0e9'
res = requests.get(url)
soup = BeautifulSoup(res.text, 'html.parser')
for hour in soup.select('.twc-hourly-forecast__table .twc-sticky-col.hourly-time > span'):
print(hour.text)
这段代码通过requests库获取网站的