网页抓取Yahoo Finance建议评级

时间:2020-03-23 12:33:51

标签: web-scraping beautifulsoup yahoo-finance

我正在尝试使用BeautifulSoup刮取Yahoo的《财务建议评级》,但它始终返回“无”。 例如。 AAPL的推荐等级为“ 2” https://finance.yahoo.com/quote/AAPL/analysis?p=AAPL

请告知。谢谢!

下面是代码:

from requests import get
from bs4 import BeautifulSoup

tickers = ['AAPL']
url = 'https://sg.finance.yahoo.com/quote/%s/profile?p=%s'%(ticker, ticker)
print(url)
response = get(url)

html_soup = BeautifulSoup(response.text, 'html.parser')
type(html_soup)

#yf_rec refers to yahoo finance recommendation

try:
    yf_rec = html_soup.find('div', attrs={'class':'B(8px) Pos(a) C(white) Py(2px) Px(0) Ta(c) Bdrs(3px) Trstf(eio) Trsde(0.5) Arrow South Bdtc(i)::a Fw(b) Bgc($buy) Bdtc($buy)'}).text.strip()
except:
    pass

print(yf_rec)

0 个答案:

没有答案