【问题标题】:Download a PNG from URL LookIntoBitcoin从 URL LookIntoBitcoin 下载 PNG
【发布时间】:2021-11-06 14:56:08
【问题描述】:

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

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

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

【问题讨论】:

  • 它是动态生成的,最简单的就是使用 Selenium
  • 是的,正如 Martheen 所说,它是动态生成的 →at client side←。 Selenium 或 PhantomJS (phantomjs.org) 应该可以解决您的问题

标签: image url download png bitcoin


【解决方案1】:

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

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

  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": [
              "$0.001",
              ...
              "$10,000",
              "$100,000"
            ],
            "tickvals": [
              0.001,
              ...
              100000
            ],
            "title": {
              "text": "BTC Price (USD)"
            },
            "type": "log",
            "zeroline": true
          }
        }
      }
    }
  }
}

【讨论】:

  • 谢谢,看来我别无选择。但是该死,为了得到一个图像文件而付出了这么多努力。我可能只需要搁置它。谢谢你的帮助。
猜你喜欢
  • 2017-10-17
  • 1970-01-01
  • 1970-01-01
  • 2015-11-12
  • 2012-10-04
  • 2015-01-16
  • 2013-02-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多