for url in indexurls:
row = parseFormPage(indexurls)
row
indexurls
是一个充满URL的列表
返回错误,而不是遍历列表。 需要迭代方面的帮助! 这是功能代码
def parseFormPage(indexurls):
'''
Input: URL
Output:
filer_cik:
filing_date:
report_date:
form_url
'''
# get page and create soup
res = requests.get(indexurls)
html = res.text
soup = BeautifulSoup(html, 'html.parser')
# parse filer Info on 10K page
filer_div = soup.find('div', {'id': 'filerDiv'})
filer_text = filer_div.find('span', {'class': 'companyName'}).find('a').get_text()
filer_cik = re.search(r"(\d{10})\s(\(.+\))$" ,filer_text)[1]
# parse 10K Page Meta data
form_content = soup.find('div', {'class': 'formContent'})
filing_date = form_content.find('div', text='Filing Date').findNext('div').get_text()
report_date = form_content.find('div', text='Period of Report').findNext('div').get_text()
# parse 10-K URL
table = soup.find('table', {'class': 'tableFile', 'summary': 'Document Format Files'})
href = table.find('td', text='10-K').find_parent('tr').find('a')['href']
form_url = "https://www.sec.gov" + href
return filer_cik, filing_date, report_date, form_url
错误如下
这就是下面的错误,我认为这更多的是列表的问题
InvalidSchema: No connection adapters were found for '['https://www.sec.gov/Archives/edgar/data/1599407/0001477932-16-009759-index.htm']
这是一个示例:https://www.sec.gov/Archives/edgar/data/1599407/0001477932-16-009759-index.htm
预期输出应为以下列表:
('0001606163',
'2016-03-21',
'2015-12-31',
'https://www.sec.gov/Archives/edgar/data/1606163/000114420416089184/v434424_10k.htm')
requests.get
接受一个URL,但您正在向其传递一个列表。这就是问题所在吗要修复它,您需要更改循环:
加上重命名函数参数:
相关问题 更多 >
编程相关推荐