从 URL LookIntoBitcoin 下载 PNG

Download a PNG from URL LookIntoBitcoin

有一个页面URL: https://www.lookintobitcoin.com/charts/1-year-hodl-wave/

我正在设计一个页面,我只想引用此 URL 的“图像”。 它有一个下载的 PNG 文件,我怎样才能得到这个 png 图像文件的 path/url?

这是图像图标,但我不知道如何获取 png 文件的 url 路径。 谁能告诉我如何获得它?

此图片是在客户端(浏览器)动态生成的,所以这里有两种方法可以解决您的问题:

  1. 使用Selenium or PhantomJS(均使用无头浏览器技术)模拟浏览器行为并在后台自动“按下”下载按钮。

  2. 获取JSON数据并自行创建图表(例如how to create PNG image based on txt file in python

我推荐第二种方式,因为它更灵活,您将能够广泛地自定义结果图像。但它可能比无头浏览器方式更复杂。

如果您想使用第二种方式,您可以使用 python 获取 JSON 数据(例如):

import requests
import json

url = 'https://www.lookintobitcoin.com/django_plotly_dash/app/hodl_wave/_dash-update-component'
request_data = {
  "output":"chart.figure",
  "changedPropIds":["url.pathname"],
  "inputs":[
    {
      "id":"url",
      "property":"pathname",
      "value":"/charts/1-year-hodl-wave/"
    }
  ]
}

response = requests.post(url, json=request_data)

print(json.dumps(response.json(), indent=2))

输出将是:

{
  "response": {
    "props": {
      "figure": {
        "data": [
          {
            "line": {
              "color": "#003366",
              "width": 1.2
            },
            "name": "BTC Price",
            "x": [
              "2010-08-17",
              "2020-09-13",
              "2020-09-14",
              ...
              "2021-09-07",
              "2021-09-08"
            ],
            "y": [
              0.07,
              0.07,
              ...
              46215.0
            ],
            "yaxis": "y2",
            "type": "scatter"
          },
          {
            "connectgaps": true,
            "line": {
              "color": "#ffa500",
              "width": 0.8
            },
            "name": "1Yr+ HODL Wave",
            "x": [
              "2010-08-17",
              ...
              "2021-12-16T00:00:00",
              "2021-12-17T00:00:00"
            ],
            "y": [
              0.28032062150000003,
              0.2807032645,
              ...
              0.5101534705064048,
              0.5090896880670537
            ],
            "yaxis": "y",
            "type": "scatter"
          },
          {
            "hoverinfo": "skip",
            "marker": {
              "color": "rgba(255, 207, 209, 0.75)",
              "size": 15
            },
            "mode": "markers",
            "name": "Price Peak",
            "showlegend": true,
            "x": [
              "2011-06-13"
            ],
            "y": [
              20.11
            ],
            "yaxis": "y2",
            "type": "scatter"
          },
          {
            "hoverinfo": "skip",
            "marker": {
              "color": "rgba(255, 207, 209, 0.75)",
              "size": 15
            },
            "mode": "markers",
            "name": "Price Peak",
            "showlegend": false,
            "x": [
              "2011-06-13"
            ],
            "y": [
              0.2979442568
            ],
            "yaxis": "y",
            "type": "scatter"
          },
          {
            "hoverinfo": "skip",
            "marker": {
              "color": "rgba(255, 207, 209, 0.75)",
              "size": 15
            },
            "mode": "markers",
            "name": "Price Peak",
            "showlegend": false,
            "x": [
              "2013-12-02"
            ],
            "y": [
              1047.9
            ],
            "yaxis": "y2",
            "type": "scatter"
          },
          {
            "hoverinfo": "skip",
            "marker": {
              "color": "rgba(255, 207, 209, 0.75)",
              "size": 15
            },
            "mode": "markers",
            "name": "Price Peak",
            "showlegend": false,
            "x": [
              "2013-12-02"
            ],
            "y": [
              0.3877138953
            ],
            "yaxis": "y",
            "type": "scatter"
          },
          {
            "hoverinfo": "skip",
            "marker": {
              "color": "rgba(255, 207, 209, 0.75)",
              "size": 15
            },
            "mode": "markers",
            "name": "Price Peak",
            "showlegend": false,
            "x": [
              "2017-12-20"
            ],
            "y": [
              16811.3
            ],
            "yaxis": "y2",
            "type": "scatter"
          },
          {
            "hoverinfo": "skip",
            "marker": {
              "color": "rgba(255, 207, 209, 0.75)",
              "size": 15
            },
            "mode": "markers",
            "name": "Price Peak",
            "showlegend": false,
            "x": [
              "2017-12-20"
            ],
            "y": [
              0.43133634880000005
            ],
            "yaxis": "y",
            "type": "scatter"
          },
          {
            "hoverinfo": "skip",
            "marker": {
              "color": "rgba(211, 245, 231, 0.75)",
              "size": 15
            },
            "mode": "markers",
            "name": "Price Bottom",
            "showlegend": false,
            "x": [
              "2011-11-22"
            ],
            "y": [
              2.31
            ],
            "yaxis": "y2",
            "type": "scatter"
          },
          {
            "hoverinfo": "skip",
            "marker": {
              "color": "rgba(211, 245, 231, 0.75)",
              "size": 15
            },
            "mode": "markers",
            "name": "Price Bottom",
            "showlegend": false,
            "x": [
              "2011-11-22"
            ],
            "y": [
              0.3073864328
            ],
            "yaxis": "y",
            "type": "scatter"
          },
          {
            "hoverinfo": "skip",
            "marker": {
              "color": "rgba(211, 245, 231, 0.75)",
              "size": 15
            },
            "mode": "markers",
            "name": "Price Bottom",
            "showlegend": false,
            "x": [
              "2015-01-17"
            ],
            "y": [
              201.75
            ],
            "yaxis": "y2",
            "type": "scatter"
          },
          {
            "hoverinfo": "skip",
            "marker": {
              "color": "rgba(211, 245, 231, 0.75)",
              "size": 15
            },
            "mode": "markers",
            "name": "Price Bottom",
            "showlegend": false,
            "x": [
              "2015-01-17"
            ],
            "y": [
              0.5363931366
            ],
            "yaxis": "y",
            "type": "scatter"
          },
          {
            "hoverinfo": "skip",
            "marker": {
              "color": "rgba(211, 245, 231, 0.75)",
              "size": 15
            },
            "mode": "markers",
            "name": "Price Bottom",
            "showlegend": true,
            "x": [
              "2018-12-20"
            ],
            "y": [
              3983.01
            ],
            "yaxis": "y2",
            "type": "scatter"
          },
          {
            "hoverinfo": "skip",
            "marker": {
              "color": "rgba(211, 245, 231, 0.75)",
              "size": 15
            },
            "mode": "markers",
            "name": "Price Bottom",
            "showlegend": false,
            "x": [
              "2018-12-20"
            ],
            "y": [
              0.5097358173
            ],
            "yaxis": "y",
            "type": "scatter"
          }
        ],
        "layout": {
          "hovermode": "closest",
          "images": [
            {
              "layer": "below",
              "opacity": 0.1,
              "sizex": 0.4,
              "sizey": 0.4,
              "source": "https://www.lookintobitcoin.com/static/img/logo/logo-stacked.png",
              "x": 0.4,
              "xref": "paper",
              "y": 0.75,
              "yref": "paper"
            }
          ],
          "legend": {
            "font": {
              "color": "#696969"
            },
            "orientation": "h",
            "x": 0.1
          },
          "margin": {
            "t": 10
          },
          "uirevision": "False",
          "xaxis": {
            "color": "#696969",
            "gridcolor": "#d3d3d3",
            "hoverformat": "%d-%b-%y",
            "range": [
              "2010-08-17",
              "2021-12-17T00:00:00"
            ],
            "showline": true,
            "showspikes": true,
            "spikecolor": "#696969",
            "spikedash": "solid",
            "spikemode": "toaxis+across",
            "spikethickness": 1
          },
          "yaxis": {
            "color": "#696969",
            "hoverformat": "%",
            "range": [
              0,
              1
            ],
            "showgrid": false,
            "showspikes": true,
            ...
            "spikethickness": 1,
            "tickformat": "%",
            "title": {
              "text": "1Yr+ HODL Wave"
            }
          },
          "yaxis2": {
            "color": "#696969",
            "dtick": 1,
            ...
            "spikethickness": 1,
            "ticktext": [
              "[=11=].001",
              ...
              ",000",
              "0,000"
            ],
            "tickvals": [
              0.001,
              ...
              100000
            ],
            "title": {
              "text": "BTC Price (USD)"
            },
            "type": "log",
            "zeroline": true
          }
        }
      }
    }
  }
}