【问题标题】:beautifulsoup parsing table with no id or class attributes in PythonPython中没有id或类属性的beautifulsoup解析表
【发布时间】:2017-06-01 18:23:53
【问题描述】:

我正在尝试使用beautifulsoup来解析下面url中表格中的数据,

http://hk.warrants.com/home/en/sgdata/list_e.cgi#topsearch

由于表没有类属性或id,我不能使用soup.find("table", {"title":"TheTitle"}) 的正常方法来定位表。相反,我试过了,

warrantUrl = 'http://hk.warrants.com/home/en/sgdata/list_e.cgi#topsearch'
warrantPage = urlopen(warrantUrl)
soup = BeautifulSoup(warrantPage, 'html.parser')
table = soup.find_all("tr")
paragraphs = []
for x in table:
    paragraphs.append(str(x))

另外,我尝试了这篇文章中提到的方法, Parse table with BeautifulSoup Python 。但是没有成功...

【问题讨论】:

    标签: python beautifulsoup


    【解决方案1】:

    本站使用javascript,BeautifulSoup不能转html,不能处理,urllib也不能,需要查看Ghost for python。

    http://jeanphix.me/Ghost.py/

    阅读文档,它真的很简单,功能强大并且类似于请求。它能够“评估”javascript并以各种方式返回它们的值。

    【讨论】:

    • 检查一下,如果您需要任何帮助,请不要犹豫
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-16
    • 2017-09-12
    • 1970-01-01
    • 2020-04-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多