爬取天气气温

http://www.weather.com.cn/textFC/hn.shtml

在这里插入图片描述

import re, requests
from pyecharts import Bar

DATAS = []# 将总数据设置为全局变量

def parse_page(url):
    headers = {
        'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36"
    }
    response = requests.get(url, headers=headers)
    content = response.content.decode("utf-8")
    cities = re.findall(r'<td width="83" height="23">.*?<a.*?>(.*?)</a>', content, re.DOTALL)
    len_ = int(len(cities)/7)
    cities = cities[0:len_]
    temps = re.findall(r'<td width="86">(\d+?)</td>', content, re.DOTALL)
    temps = temps[0:len_]

    for value in zip(cities, temps):
        city, temp = value
        

猜你喜欢

转载自blog.csdn.net/weixin_44510615/article/details/99664446