【问题标题】:I want to extract vwap value from the given webpage我想从给定的网页中提取 vwap 值
【发布时间】:2019-05-01 20:33:22
【问题描述】:
from bs4 import BeautifulSoup as BS
url="https://nseindia.com/live_market/dynaContent/live_watch/get_quote/GetQuote.jsp?symbol=KOTAKBANK&illiquid=0&smeFlag=0&itpFlag=0"

page=urllib.request.Request(url,headers={'User-Agent': 'Mozilla/5.0'}) 
infile=urllib.request.urlopen(page).read()
data = infile.decode('ISO-8859-1') # Read the content as string decoded with ISO-8859-1


print (soup.find('span', {'id':'vwap'}).text)

我在 jupyter 中运行这段代码;我希望输出在网页上显示为 VWAP 的值,但没有任何内容显示为输出。

【问题讨论】:

    标签: python html web-scraping


    【解决方案1】:

    您可以从一个不同的标签中提取,该标签的字符串包含很多有用的信息,包括使用json加载后的价格

    import requests
    import json
    from bs4 import BeautifulSoup as bs
    
    r = requests.get('https://nseindia.com/live_market/dynaContent/live_watch/get_quote/GetQuote.jsp?symbol=KOTAKBANK&illiquid=0&smeFlag=0&itpFlag=0')
    soup = bs(r.content, 'lxml')
    data = json.loads(soup.select_one('#responseDiv').text.strip())
    print(data['data'][0]['averagePrice'])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多