【问题标题】:BeautifulSoup findall returning empty listBeautifulSoup findall 返回空列表
【发布时间】:2015-02-24 23:20:02
【问题描述】:

所以我对 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 之前存在。这就是为什么你不能以这种方式得到它们

标签: python beautifulsoup findall


【解决方案1】:

数据由 javascript 填充,beautifulsoup 不会解释:你得到的是原始容器。

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

祝你好运(我确实设法重播了 curl 的数据请求,所以在 python 中应该是可行的)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多