当汤产生时,文本消失

2024-04-18 02:27:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从雅虎财经网站上提取日期,但当文本为“生成”时,只显示时间而不显示日期

import requests
import re
from bs4 import BeautifulSoup

technicals = {}
ticker = "INFY.NS"

try:
    url = "https://finance.yahoo.com/quote/" + ticker + "/key-statistics?p=" + ticker
    r = requests.get(url)
    # soup = BeautifulSoup(open("Yahoo Stats.html"), 'lxml')
    soup = BeautifulSoup(r.text, 'lxml')
    t = soup.find('span', {"class": "Trsdu(0.3s) Fw(b) Fz(36px) Mb(-4px) D(ib)"})
    technicals["CMP"] = t.text
    # d = soup.find('span', {"class": "C($tertiaryColor) D(b) Fz(12px) Fw(n) Mstart(0)--mobpsm Mt(6px)--mobpsm"})
    d = soup.find('div', attrs={'id': 'quote-market-notice'})
    print(d.text)

该代码在上一页上运行得更远

有人能帮你弄到日期和时间吗