G
G
GreenX52020-06-14 09:26:02
Python
GreenX5, 2020-06-14 09:26:02

Parsing data from a widget on a local page?

Polling data acc. and parsing once a second, in order to avoid waiting for responses to a request from a remote page, I placed the service widget on a local page, I open it once with a Google driver and read it as often as I need. The problem is that the browser sees the incoming values, but it doesn’t work to take it for parsing, I see the script and some kind of nonsense. Please help me with a working example, if it is feasible in principle.

Widget page on drive C

spoiler
<!DOCTYPE html>
<head>
<meta http-equiv=Content-Type content="text/html;charset=UTF-8">
<title>ind</title>
</head>
<body>

<!-- TradingView Widget BEGIN -->
<div class="tradingview-widget-container">
  <div class="tradingview-widget-container__widget"></div>
  <div class="tradingview-widget-copyright">
  <a href="https://www.tradingview.com/markets/indices/" rel="noopener" target="_blank">
  <span class="blue-text">Indices</span></a> by TradingView</div>
  <script type="text/javascript" src="https://s3.tradingview.com/external-embedding/embed-widget-market-quotes.js" async>
  {
  "width": 770,
  "height": 450,
  "symbolsGroups": [
    {
      "name": "Indices",
      "originalName": "Indices",
      "symbols": [
        {
          "name": "XETR:DAX",
          "displayName": "DAX"
        },
        {
          "name": "CURRENCYCOM:VIX",
          "displayName": "VIX"
        },
        {
          "name": "CURRENCYCOM:US500",
          "displayName": "SIP"
        },
        {
          "name": "CME:SP1!",
          "displayName": "FSIP"
        }
      ]
    }
  ],
  "colorTheme": "light",
  "isTransparent": false,
  "locale": "en"
}
  </script>
</div>
<!-- TradingView Widget END -->

</body>


parser

spoiler
from selenium import webdriver
import time
from bs4 import BeautifulSoup

options = webdriver.ChromeOptions()
#options.add_argument('headless')

browser = webdriver.Chrome(options=options)
browser.get('file:///C:/start/ind.html')
time.sleep(5)

page = browser.page_source
soup = BeautifulSoup(page, 'html.parser')

print(soup)

browser.quit()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-06-14
@GreenX5

All data in the iframe is

iframe = browser.execute_script("return document.getElementsByTagName('iframe')[0]")
browser.switch_to_frame(iframe)

page = browser.page_source
print(page)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question