【问题标题】:beautiful soup and requests not getting full page [duplicate]美丽的汤和请求没有得到整页[重复]
【发布时间】:2014-11-14 23:29:10
【问题描述】:

我的代码如下所示。

from bs4 import BeautifulSoup
import requests

r  = requests.get("http://www.data.com.sg/iCurrentLaunch.jsp")
data = r.text
soup = BeautifulSoup(data)
n = soup.findAll('table')[7].findAll('table')
for tab in n:
    print tab.findAll('td')[1].text

我得到的是直到 IDYLLIC SUITES 之前的属性名称,之后我收到错误“列表索引超出范围”。有什么问题?

【问题讨论】:

标签: python web-scraping beautifulsoup python-requests


【解决方案1】:

我不确定到底是什么在困扰您。因为当我尝试您的代码(原样)时,它对我有用。

仍然,尝试更改解析器,可能是 html5lib

这样吧,

pip 安装 html5lib

然后将代码更改为,

from bs4 import BeautifulSoup
import requests

r  = requests.get("http://www.data.com.sg/iCurrentLaunch.jsp")
data = r.text
soup = BeautifulSoup(data,'html5lib') # Change of Parser
n = soup.findAll('table')[7].findAll('table')
for tab in n:
    print tab.findAll('td')[1].text

如果有帮助请告诉我

【讨论】:

  • 三个解析器的输出都是一样的。
  • 更改解析器对我有用。谢谢
  • 我不知道是什么问题我尝试了lxml解析器它给出了“list out of index”的错误
猜你喜欢
  • 1970-01-01
  • 2018-10-15
  • 2016-05-19
  • 1970-01-01
  • 1970-01-01
  • 2020-04-13
  • 2018-09-04
  • 1970-01-01
相关资源
最近更新 更多