python - 通过 websockets 抓取数据

标签 python web-scraping encoding websocket scrapy

我正在尝试从此特定网页获取每日价格数据:

https://www.londonstockexchange.com/stock/CS1/amundi/company-page

这些数据显示在图表中。

我想不出要获取这些数据的想法。我假设这些数据是通过在浏览器控制台中建立和检索的 websocket 连接之一传输的。

enter image description here

我尝试模拟 websocket 连接并发送与前端应用程序相同的二进制文件。

from websocket import create_connection

s = create_connection("wss://82-99-29-151.infrontservices.com/wsrt/2/4")

hex_1 = "3e000000010..."
hex_2 = "13000000010..."
hex_3 = "1e000000010..."

ws.send(binascii.unhexlify(hex_1))
ws.send(binascii.unhexlify(hex_2))
ws.send(binascii.unhexlify(hex_3))

result =  ws.recv()

然后我尝试使用以下所有可能的编码来解码此响应:

import binascii
from encodings.aliases import aliases

for v in [v for k, v in aliases.items()]:
    try:
        print(result.decode(v))
    except:
        print(f"ERROR {v}")

当然,我没有可以利用的可解释输出。我可以认为这里使用了密码。但我不知道如何进一步调查。

你知道吗? :)

提前致谢!

艾尔科

编辑 1

enter image description here

我们可以看到一个给定日期的值为 16990 的数据点。这就是我要找的是图表的整个时间序列。

最佳答案

在您阅读我的评论并了解有关抓取的信息并决定谨慎行事后,

Python 只需几行代码就可以检索这个 JSON

import requests
url = "https://api.londonstockexchange.com/api/gw/lse/instruments/alldata/CS1"
response = requests.get(url=url).json()
# print some data from the json
print(response_json)
print(response_json.get("description"))
print(response_json.get("bid"))

我使用“网络”选项卡找到了这些数据,当您点击“重新加载”时又出现了一些数据,但它们似乎是空的。

关于python - 通过 websockets 抓取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62409366/

相关文章:

python - spaCy 的正则表达式与 Python 的正则表达式不同

python - 为什么这个循环不停止?

java - "view page source"上不可见的 html 元素

html - 是否可以通过请求和 BeautifulSoup 获取 eBay 商品描述?

java - 拆分 jSoup 抓取结果

php - 使用 GET 从编码 UTF-8 从 URL 获取值

ios - 文件系统路径字符串的正确编码是什么?

Python Bottle 多文件上传

java - 按行分割文本文件,与平台无关

python - 由于ffmpeg不可用,matplotlib动画ArtistAnimation失败