尝试从 Yahoo Finance 中抓取一些数字,但我一直为我的一个soup.find 函数获取一个AttributeError。代码:
from bs4 import BeautifulSoup as soup
import requests
#Switch
source = requests.get('https://finance.yahoo.com/quote/SWCH?p=SWCH&.tsrc=fin- srch').text
soup = soup(source, 'lxml')
price = soup.find('span', class_=lambda x:x and set(x.split()).issuperset(set("Trsdu(0.3s) Fw(b) Fz(36px) Fw(b) D(b) Mb(-4px)".split())))
downorup = soup.find('span', class_=lambda x:x and set(x.split()).issuperset(set("Trsdu(0.3s) Fw(500) Pstart(10px) Fz(24px) C($dataRed)".split())))
print("Switch stock: " + price.text + ' ' + downorup.text)
饮歌长啸
当年话下
相关分类