【问题标题】:Is there an easy way to scrape a table off a website (after a button press) using python?有没有一种简单的方法可以使用 python 从网站上刮掉一张桌子(按下按钮后)?
【发布时间】:2020-09-20 20:56:57
【问题描述】:

我正试图从这个website 上刮下一张桌子。游戏日志表是典型的格式化 html 表,但有一个按钮 可以将表转换为更容易解析的 csv 数组。我想知道是否有一种简单的方法(在 python 中)通过模拟按钮单击来下载 csv 数组。我试过 selenium,但这似乎打开了一个 chrome 浏览器(我不想这样做)。必须有更简单的方法!

谢谢,

杰西

【问题讨论】:

    标签: python html web-scraping python-requests


    【解决方案1】:

    来自@satyaganesh987 博客:

    import pandas as pd
    URL = "https://en.wikipedia.org/wiki/Cricket_World_Cup"
    tables = pd.read_html(URL,match="Performance details")
    print("There are : ",len(tables)," tables")
    print("Take look at table 0")
    tables[0]
    

    更多信息请查看博客:Scraping Table Data From Websites— using a single line in Python

    【讨论】:

      【解决方案2】:

      网站的作者正在使用 Javascript 将表格转换为 CSV 格式。 在这种情况下,Selenium 是一种您不喜欢的方法,或者只是采用 HTML 版本的表格并在 Python 中编写一个等效的函数,将 HTML 表格转换为 CSV。

      他们正在使用this library

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-15
        • 2020-04-26
        • 2018-02-04
        • 2023-03-27
        • 2019-02-18
        • 2012-12-25
        • 2021-11-01
        • 2013-06-15
        相关资源
        最近更新 更多