python - BeautifulSoup findall 返回空列表

标签 python beautifulsoup findall

所以我对 python 很陌生,我正在尝试使用 bs4 和 urllib 从 iso-ne.com/isoexpress/的表中获取数据。这是我到目前为止所拥有的:

from bs4 import BeautifulSoup
from urllib import urlopen
website='http://www.iso-ne.com/isoexpress/'
html=urlopen(website).read().decode('utf-8')
soup=BeautifulSoup(html, 'html.parser')
table=soup.find('div', {'class': 'chart'})
rows=table.find_all('tr')
for tr in rows:
   col=tr.find_all('td')
    for td in col:
        text=td.find_all(class_='lmp-list-energy')
        print text

当我运行这个时,我得到 6 个空括号:

[]
[]
[]
[]
[]
[]

我想要获取的数据是 iso-ne 网站上新罕布什尔州的五分钟实时 LMP 价格

最佳答案

数据由 javascript 填充,不被 beautifulsoup 解释:您将获得原始容器。

我会做什么(但我会检查合法性和条件...):查看对后端所做的请求(例如,通过使用 chrome 上的网络模式) => 你会发现调用http://iso-ne.com/ws/wsclient的东西。获取客户端发送的参数(cookie...)并重放请求(或通过反复试验微调参数)。

祝你好运(我确实成功地重播了来自curl的数据请求,所以它应该可以在python中实现)

关于python - BeautifulSoup findall 返回空列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28708319/

相关文章:

python - 在 Folium 中将透明度样式传递给 GeoJSON

python - div 内漂亮的 Soup 解析表

python - 根据列值创建列表,并使用该列表从 df 中的字符串列中提取单词,而不用 for 循环覆盖行值

python - 第一个纪元后 Keras/tensorflow 'ValueError: output of generator should be a tuple...' 错误

python - 使用 PyDrive 访问共享文件

python - 将 `AMPL` 或 `GAMS` 文件转换为 `Python`

python - 关于python3.6当我导入bs4时,不起作用

python - 使用 Python 和 BeautifulSoup 从公共(public)目录中获取信息

python - 使用正则表达式查找字符串中的所有小写字母附加到列表。 Python

java - 如何使用 findAll() 仅返回特定信息而不是所有信息?