Requests won't get the text from web page?

前端 未结 2 486
抹茶落季
抹茶落季 2021-01-23 14:55

I am trying to get the value of VIX from a webpage.

The code I am using:

raw_page = requests.get(\"https://www.nseindia.com/live_market/dynaContent/live         


        
2条回答
  •  有刺的猬
    2021-01-23 15:50

    The data you're looking for, is not available in the page source. And requests.get(...) gets you only the page source without the elements that are dynamically added through JavaScript. But, you can still get it using requests module.

    In the Network tab, inside the developer tools, you can see a file named VixDetails.json. A request is being sent to https://www.nseindia.com/live_market/dynaContent/live_watch/VixDetails.json, which returns the data in the form of JSON.

    You can access it using the built-in .json() function of the requests module.

    r = requests.get('https://www.nseindia.com/live_market/dynaContent/live_watch/VixDetails.json')
    data = r.json()
    vix_price = data['currentVixSnapShot'][0]['CURRENT_PRICE']
    print(vix_price)
    # 15.7000
    

提交回复
热议问题