BeautifulSoup找到返回空列表

时间:2015-02-24 23:20:03

标签: python beautifulsoup findall

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

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价格

1 个答案:

答案 0 :(得分:2)

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

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

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