猿问

无法从自刷新的 websocket 端点获取页面源/DOM

这是在添加更多文本数据的同时自我刷新的网站。在 Chrome 中,查看页面源代码将不起作用,因为它会无限期地给出空白结果,因此我通常使用 Inspect 来查看源代码。


使用硒,无论我是否使用,我似乎都无法获取源代码


browser = webdriver.Chrome(executable_path = path_to_chromedriver, chrome_options=options)


html_source = browser.page_source

print html_source

或者


browser = webdriver.Chrome(executable_path = path_to_chromedriver, chrome_options=options)


html_source = browser.find_elements_by_xpath("//*")

print html_source

我想要的数据只是作为 html 正文中的文本出现


<body>

<pre style="word-wrap: break-word; white-space: pre-wrap;">: 

: -1

: -1

: -1

</pre>

</body>

“-1”表示来自 TradingView 服务器的心跳。请注意,TradingView 没有官方的公共 websockets API,因此这是我试图利用的他们自己的内部端点。


慕莱坞森
浏览 194回答 1
1回答

动漫人物

这是因为它不是 html 页面而是实时流或text/event-stream,尝试使用requestswithstream=Trueimport requestsr = requests.get('https://.....', stream=True)for line in r.iter_lines():&nbsp; &nbsp; print(line.decode("utf-8"))回复:&nbsp;: -1: -1: -1
随时随地看视频慕课网APP

相关分类

Python
我要回答