我正在抓取一家银行的收益发布网站,以获取每个季度发布的PDF链接。每个季度部分都有一个标题(例如:2020年第一季度等)。我在获取报告方面没有问题,但我也希望每个报告都有相应的部分标题。以下是我目前掌握的情况:
import requests
from bs4 import BeautifulSoup
import urllib3
def scraper():
urllib3.disable_warnings()
FITBurl = "https://ir.53.com/annual-and-quarterly-results"
FITBr = requests.get(url=FITBurl, verify=False)
FITBsoup = BeautifulSoup(FITBr.text,'html.parser')
#finds quarter name
quarter = FITBsoup.find_all("h4")[0].text
print(quarter) # I want this respective 'quarter' name for each earnings release
mylist = {}
for items in FITBsoup.find_all("div", class_="filefield-file"): #add [0:5] to the end to just get the latest
for x in items.select("a"):
title = x.text.strip()
name = x['title'][:-4]
if title == 'Quarterly Earnings Release':
link = x['href']
print(f'{title} {name}: {link}') # ideally quarter name would replace 'name'
mylist[name] = link
scraper()
我试图将它添加到我的循环中,但它只是为每个“h4”标题生成所有输出,这是不对的。这看起来很简单,但它真的让我感到困惑。有什么建议吗
使用下面的css选择器,然后迭代
输出:
相关问题 更多 >
编程相关推荐