url="https://lishi.tianqi.com/hangzhou/202212.html"
headers={'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/108.0.1462.54"}
r=requests.get(url, headers=headers,timeout = 30)
r.encoding = "utf-8"
time.sleep(6)
text=r.text
pattern =re.compile('<div class="th140">(.*?)div>',re.S)
results = re.findall(pattern,text)
results
怎么样可以只提取最高温度和最低温度
然后写入txt文件之后呈现这个形式
get函数的后面加一个json()。然后就可以用字典取值的方式取值了