【问题标题】:Text vanishes when soup produces汤产生时文本消失
【发布时间】:2020-08-30 07:50:26
【问题描述】:

我正在尝试从雅虎财经网站提取日期,但是当文本生成时,只显示时间而不显示日期

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)

代码继续运行。

谁能帮忙获取日期和时间

【问题讨论】:

    标签: python beautifulsoup yahoo-finance


    【解决方案1】:

    当我检查页面源时,数据不在 span 标记中。好像是动态加载的。

    <span data-reactid="36">At close:  3:30PM IST</span>
    

    我建议您改用 Selenium 库来获取所需的数据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-14
      • 1970-01-01
      • 1970-01-01
      • 2023-01-12
      • 1970-01-01
      • 2014-02-27
      • 2011-08-25
      • 1970-01-01
      相关资源
      最近更新 更多