我正试图使用美国证券交易委员会(SEC)的数据库,查看公司财务报告(称为10k),为每次提交拿出一份执行委员会成员名单。我目前正在使用微软(股票代码:MSFT)和沃尔玛(股票代码:WMT)的最新文件。我知道我可以在其他金融网站上查找这些信息,但我正在尝试建立一个灵活的数据库供个人使用。我的问题:
我开始认为我可能无法自动执行此操作,因为缺少在每个文件中唯一且在所有文件中通用的标识符。在过去的几周里,我看了很多Python网页垃圾教程和视频,真是头痛不已。任何建议都会得到赞赏,完全自动化将是理想的,这样我就可以循环通过多个文件,部分帮助我在这里学习。我可能会碰到尝试自动化一些太多样化的东西
微软链接:
https://www.sec.gov/Archives/edgar/data/789019/000156459019027952/msft-10k_20190630.htm
所需表格:
<table border="0" cellspacing="0" cellpadding="0" align="center" style="border-collapse:collapse; width:100%;">
沃尔玛链接:
https://www.sec.gov/Archives/edgar/data/104169/000010416919000016/wmtform10-kx1312019.htm
所需表格:
<table cellpadding="0" cellspacing="0" style="font-family:Times New Roman;font-size:10pt;width:100%;border-collapse:collapse;text-align:left;">
计算每页表数的代码:
from selenium import webdriver
from bs4 import BeautifulSoup
chrome_path = r"C:\webdrivers\chromedriver.exe"
browser = webdriver.Chrome(chrome_path)
#Microsoft
browser.get("https://www.sec.gov/Archives/edgar/data/789019/000156459019027952/msft-10k_20190630.htm")
msft = browser.page_source
page_msft = BeautifulSoup(msft, 'html.parser')
tables_msft = page_msft.find_all("table")
#Walmart
browser.get("https://www.sec.gov/Archives/edgar/data/104169/000010416919000016/wmtform10-kx1312019.htm")
wmt = browser.page_source
page_wmt = BeautifulSoup(wmt, 'html.parser')
tables_wmt = page_wmt.find_all("table")
print("MSFT Result Table Count: " + str(len(tables_msft)))
print("Walmart Result Table Count: " + str(len(tables_wmt)))
结果:
MSFT结果表计数:263
沃尔玛结果表计数:258
进程已完成,退出代码为0
首先,您不需要Selenium,请求库将更快并避免开销。因此,我能够部分地找到提取所需数据的方法。但是由于列数不同,它们不能组合在一起(对于微软和沃尔玛)。 下面的代码生成两个必需的数据帧,一个用于Microsoft,一个用于Walmart。 您仍然需要操纵列名。这样做的目的是获取td值为“Age”的表,因为它是唯一的表数据。如果您需要澄清,请告诉我:-
相关问题 更多 >
编程相关推荐