我正在嘗試從以下URL中提取 html 表。例如,第 44 頁的 2019 年董事薪酬表。我相信該表沒有特定的 id,例如“薪酬表”等。要提取該表,我只能想到匹配的列名稱或關鍵字,例如“股票獎勵”或“所有其他補償”,然后抓取關聯的表。有沒有一種簡單的方法可以根據列名提取這些表?或者也許有更簡單的方法?謝謝!我在抓取 HTML 表方面相對較新..我的代碼如下from bs4 import BeautifulSoupimport requestsurl = 'https://www.sec.gov/Archives/edgar/data/66740/000120677420000907/mmm3661701-def14a.htm'r = requests.get(url)?soup = BeautifulSoup(r.text, 'html.parser')rows = soup.find_all('tr')
1 回答

www說
TA貢獻1775條經驗 獲得超8個贊
當然,您可以根據文檔pandas
?read_html
使用函數 usingmatch
和 來做到這一點。attrs
import pandas as pd
df = pd.read_html(
? ? "https://www.sec.gov/Archives/edgar/data/66740/000120677420000907/mmm3661701-def14a.htm", attrs={'style': 'border-collapse: collapse; width: 100%; font: 9pt Arial, Helvetica, Sans-Serif'}, match="Non-Employee Directors")
print(df)
df[0].to_csv("data.csv", index=False, header=False)
輸出:
- 1 回答
- 0 關注
- 128 瀏覽
添加回答
舉報
0/150
提交
取消