【发布时间】:2017-08-06 23:34:35
【问题描述】:
我正在通过从https://www.wunderground.com/(随机搜索邮政编码)获取基本天气数据(例如每日高温/低温)来练习网络爬虫。
我尝试了我的代码的各种变体,但它一直返回一个空列表,温度应该在哪里。老实说,我只是不知道自己哪里出错了。谁能指出我正确的方向?
import requests
from bs4 import BeautifulSoup
response=requests.get('https://www.wunderground.com/cgi-bin/findweather/getForecast?query=76502')
response_data = BeautifulSoup(response.content, 'html.parser')
results=response_data.select("strong.high")
我还尝试过执行以下操作以及其他各种变体:
results = response_data.find_all('strong', class_ = 'high')
results = response_data.select('div.small_6 columns > strong.high' )
【问题讨论】:
-
内容在运行时呈现。所以你不能通过
requests获得它。您最好使用能够获取 JavaScript、JSON 等并更新 DOM 的浏览器。
标签: python web-scraping beautifulsoup