weixin_47344019 2024-01-24 12:39 采纳率: 0%
浏览 12

抓取天气预报网页时出现问题

想从网站上爬点气象数据,按照以下代码试了好几天,也换了好几种,都不能得到自己想要的内容
是我的代码有问题吗,还是其他问题?

import requests
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/7602dc8c53254ac499248e6dd0a089ad.jpeg "#left")

import bs4
headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36"}
response=requests.get("http://weather.sz.gov.cn/",headers=headers)
soup=bs4.BeautifulSoup(response.text,"lxml")
soup.encode('utf-8')
forecast_list=soup.find_all(id='yb_day')
print(forecast_list)
for forecast in forecast_list:
    print(forecast)
  • 写回答

2条回答 默认 最新

  • 小辰代写 2024-01-24 13:05
    关注

    代码没问题,问题是你试图直接从页面中请求数据而不是数据库中,甚至还是官方的页面,
    讲个笑话,我刚刚在测试你的代码的时候因为发送非法请求现在被官方拉黑了

    评论 编辑记录

报告相同问题?

问题事件

  • 创建了问题 1月24日