我正在尝试用Python3抓取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)发布于 2020-05-12 07:51:51
我发现你的数据包含多个主体。很抱歉我之前没有注意到这一点。看看下面的代码是否可以工作。
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))https://stackoverflow.com/questions/61725323
复制相似问题