How can I scrape an HTML table to CSV?

后端 未结 11 1340
悲&欢浪女
悲&欢浪女 2020-11-29 21:56

The Problem

I use a tool at work that lets me do queries and get back HTML tables of info. I do not have any kind of back-end access to it.

A lot of this inf

11条回答
  •  迷失自我
    2020-11-29 22:18

    Two ways come to mind (especially for those of us that don't have Excel):

    • Google Spreadsheets has an excellent importHTML function:
      • =importHTML("http://example.com/page/with/table", "table", index
      • Index starts at 1
      • I recommend a copy and paste values shortly after import
      • File -> Download as -> CSV
    • Python's superb Pandas library has handy read_html and to_csv functions
      • Here's a basic Python3 script that prompts for the URL, which table at that URL, and a filename for the CSV.

提交回复
热议问题