解析年度报告的加载时间非常慢



我正在尝试使用 Python 3 抓取 SEC Edgar S&P500 年度报告,并通过一些链接接收非常慢的加载时间。我当前的代码适用于大多数报告链接,但只返回其他链接(例如,下面的链接(的网站内容的一半。

有没有办法解决这个问题?如果结果是一个没有任何奇怪的 html 字符的文本文件,并且只包含"最终用户"的所有文本,我很高兴


# import libraries
from simplified_scrapy import SimplifiedDoc,req,utils

# define the url to specific html_text file
new_html_text = r"https://www.sec.gov/Archives/edgar/data/718877/000104746919000788/0001047469-19-000788.txt"
html = req.get(new_html_text)
doc = SimplifiedDoc(html)
textfile = doc.body.text
textfile = doc.body.unescape() # Converting HTML entities
utils.saveFile("test.txt", textfile)

我发现您的数据包含多个正文。对不起,我以前没有注意到这一点。查看以下代码是否有效。

from simplified_scrapy import SimplifiedDoc,req,utils
# define the url to specific html_text file
new_html_text = r"https://www.sec.gov/Archives/edgar/data/718877/000104746919000788/0001047469-19-000788.txt"
html = req.get(new_html_text,timeout=300) # Add timeout
doc = SimplifiedDoc(html)
texts = []
bodys = doc.selects('body|BODY') # Get all
for body in bodys:
texts.append(body.unescape()) # Converting HTML entities
utils.saveFile("test.txt", "n".join(texts))

最新更新