How to extract tables from websites in Python

后端 未结 6 844
无人及你
无人及你 2020-12-04 18:18

Here,

http://www.ffiec.gov/census/report.aspx?year=2011&state=01&report=demographic&msa=11500

There is a table. My goal is to

6条回答
  •  情深已故
    2020-12-04 19:00

    You need to parse the table into an internal data structure and then output it in CSV form.

    Use BeautifulSoup to parse the table. This question is about how to do that (the accepted answer uses version 3.0.8 which is out of date by now, but you can still use it, or convert the instructions to work with BeautifulSoup version 4).

    Once you have the table in a data structure (probably a list of lists in this case) you can write it out with csv.write.

提交回复
热议问题