我正在尝试获取 sec 以获取通过输入选择的公司的所有 10-K 归档链接。该程序从 1993 年至今每年的每个季度(QTR1-4)循环。我从https://codingandfun.com/scraping-sec-edgar-python/获得代码 执行时遇到:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc3 in position 13013584: invalid continuation byte without my多年来的 for 循环和固定的年份/季度它可以工作 - 那么这里的问题是什么?
import bs4 as bs
import requests
import pandas as pd
import re
from datetime import datetime
def get_base():
company = input('Which company?: ')
filing = '10-K'
year = [*range(1993,datetime.now().year + 1)]
quarter = ['QTR1','QTR2','QTR3','QTR4']
#get all filings for each quarter(QTR1-4) in each year(beginning 1993 until actual year)
for x in year:
for y in quarter:
download = requests.get(f'https://www.sec.gov/Archives/edgar/full-index/{x}/{y}/master.idx').content
download = download.decode("utf-8").split('\n')
for item in download:
#company name and report type
if (company in item) and (filing in item):
company = item
company = company.strip()
splitted_company = company.split('|')
url = splitted_company[-1]
#build second part of the url
url2 = url.split('-')
url2 = url2[0] + url2[1] + url2[2]
url2 = url2.split('.txt')[0]
# build third part of the url
to_get_html_site = 'https://www.sec.gov/Archives/' + url
data = requests.get(to_get_html_site).content
data = data.decode("utf-8")
data = data.split('FILENAME>')
data = data[1].split('\n')[0]
#combine
url_to_use = 'https://www.sec.gov/Archives/'+ url2 + '/'+data
print(url_to_use)
get_base()