如何使用Python从交互式图表中抓取数据?

huangapple go评论147阅读模式
英文:

How to scrape data from an interactive chart using python?

问题

我想从以下链接中的“价值历史”图表中提取日期和总值数据,当图表设置为1年时:
https://csgoskins.gg/markets/csgofloat

我尝试查看网站上的数据是否存储在json文件中,但似乎不是这样。

我在查看网站的javascript代码时找到了这个,这让我认为数据存储在一个名为t的变量中,但我还没有找到它:

series: [{
                        name: "Total Value",
                        type: "line",
                        showInNavigator: !0,
                        color: "#60a5fa",
                        marker: {
                            lineColor: "#60a5fa"
                        },
                        data: t.map((function(t) {
                            return [Date.parse(t.day), t.sales_value]
                        }

这是一个名为window.createMarketValueHistoryChart = function(t)的函数的一部分。

任何帮助将不胜感激!

英文:

I would like to scrape the date and total value data from the "Value History" chart on the following link when the chart is set to 1Y:
https://csgoskins.gg/markets/csgofloat

I've tried to look and see if the data on the site is stored in a json file, but it does not seem like it.

I found this looking at the javascript code of the site, which makes me think the data is stored within a variable called t, but I haven't been able to find it:

series: [{
                        name: "Total Value",
                        type: "line",
                        showInNavigator: !0,
                        color: "#60a5fa",
                        marker: {
                            lineColor: "#60a5fa"
                        },
                        data: t.map((function(t) {
                            return [Date.parse(t.day), t.sales_value]
                        }

Which is part of a function called: window.createMarketValueHistoryChart = function(t)

Any help would be much appreciated!

答案1

得分: 0

检查控制台中的 history 变量。类似以下代码:

history.forEach(v => {console.log(v.day, v.sales_value)})

将打印出您所需的数据。


转换为 pandas

如果您使用 Chrome(但我认为对大多数浏览器都适用),在控制台中输入 history,然后按回车键,在输出上右键单击,选择 "Copy object"。将其粘贴到 data.json 文件中,然后使用以下代码读取:

df = pd.read_json('data.json')
英文:

Check the history variable in the console. Something like:

history.forEach(v => {console.log(v.day, v.sales_value)})

will print the data you need.


Getting it to pandas

If you use Chrome (but I'd assume that should work for most browsers), in the console write history, hit enter, right-click on the output, "Copy object". Paste it into data.json file and read with:

df = pd.read_json('data.json')

huangapple
  • 本文由 发表于 2023年3月7日 19:34:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/75661455.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定