简体   繁体   中英

How to extract and save a table shown in a specific tab from a website using pandas and python?

I want to extract this table http://pfam.xfam.org/family/PF00018#tabview=tab9 using python and pandas to dump into a csv file. I have tried:

import requests
import pandas as pd

url = 'http://pfam.xfam.org/family/PF00018#tabview=tab9'
html = requests.get(url).content
df_list = pd.read_html(html)
df = df_list[0]

Using all indexes available for df_list. However, the table of interest is not present.

It seems the table you wanted loaded by Javascript. Open browser's developer tool and you see they load via ajax request at http://pfam.xfam.org/family/PF00018/mapping

Building off of @hunzter's answer, here's some code to load a table from that page:

import pandas as pd

tables = pd.read_html("http://pfam.xfam.org/family/PF00018/mapping")
print(tables[0])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM