3 回答

TA贡献1824条经验 获得超6个赞
价格在那里并且可以按类别选择(id 之后第二快的选择器方法)
import requests
from bs4 import BeautifulSoup as bs
res = requests.get('https://finance.yahoo.com/quote/VXUS?p=VXUS') # https://finance.yahoo.com/quote/VTI?p=VTI
soup = bs(res.content, 'lxml')
price = soup.select_one('.Trsdu\(0\.3s\)').text
print(price)

TA贡献1810条经验 获得超4个赞
import requests
from bs4 import BeautifulSoup
response = requests.get("https://finance.yahoo.com/quote/VTI?p=VTI")
soup = BeautifulSoup(response.content, "lxml")
for stock in soup.find_all('span', class_='Trsdu(0.3s) Trsdu(0.3s) Fw(b) Fz(36px) Mb(-4px) D(b)'):
print(stock.get_text())
这将返回 141.28

TA贡献1850条经验 获得超11个赞
import requests
from bs4 import BeautifulSoup
import json
response = requests.get("https://finance.yahoo.com/quote/VTI?p=VTI")
soup = BeautifulSoup(response.content)
price = soup.findAll('script')
regularMarketPrice
a = price[-3].contents[0]
jjj = json.loads(a[111:-12])
jjj['context']['dispatcher']['stores']['StreamDataStore']['quoteData']['VTI']['regularMarketPrice']
这个可能对你有帮助,先拿到scriptdata,然后转成json,就可以找到你想要的数据了
添加回答
举报