Python 与BeautifulSoup进行网络垃圾处理,得到空列表

Python 与BeautifulSoup进行网络垃圾处理,得到空列表,python,web-scraping,beautifulsoup,Python,Web Scraping,Beautifulsoup,我通过随机搜索zipcode来获取基本的天气数据,比如每天的高低温,以此来练习拉网 我尝试了我的代码的各种变体,但它总是返回一个空列表,其中的温度应该是多少。老实说,我只是不知道我到底错在哪里。谁能给我指出正确的方向吗 import requests from bs4 import BeautifulSoup response=requests.get('https://www.wunderground.com/cgi-bin/findweather/getForecast?query=7650

我通过随机搜索zipcode来获取基本的天气数据,比如每天的高低温,以此来练习拉网

我尝试了我的代码的各种变体,但它总是返回一个空列表,其中的温度应该是多少。老实说,我只是不知道我到底错在哪里。谁能给我指出正确的方向吗

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' )

您要解析的数据是由JavaScript动态创建的,请求无法处理。您应该与或任何其他驱动程序一起使用。下面是使用selenium和:

检查元件时,可使用以下方法找到最低、最高和当前温度:

high = soup.find('strong', {'class':'high'}).text
low = soup.find('strong', {'class':'low'}).text
now = soup.find('span', {'data-variable':'temperature'}).find('span').text

您要解析的数据是由JavaScript动态创建的,请求无法处理。您应该与或任何其他驱动程序一起使用。下面是使用selenium和:

检查元件时,可使用以下方法找到最低、最高和当前温度:

high = soup.find('strong', {'class':'high'}).text
low = soup.find('strong', {'class':'low'}).text
now = soup.find('span', {'data-variable':'temperature'}).find('span').text

内容在运行时呈现。因此,您不能通过请求获得它。您最好使用一个获取JavaScript、JSON等并更新DOM的浏览器。内容在运行时呈现。因此,您不能通过请求获得它。您最好使用一个获取JavaScript、JSON等并更新DOM的浏览器。好的,谢谢!在此之前,我甚至不知道动态渲染。好吧,谢谢!在此之前,我甚至不知道动态渲染
>>> low, high, now
('25', '37', '36.5')