在没有抓取HTML的情况下从whattomine中的链接接收JSON数据

问题描述 投票:2回答:2

Explanation

This link是您输入硬件统计信息(哈希值,功率,电力成本等)后发送给您的地方。在顶部栏(在蓝色Twitter跟随按钮下方)是指向页面加载后创建的JSON文件的链接,其中输入了硬件统计信息;单击该JSON链接会将您重定向到另一个URL(https://whattomine.com/asic.json)。

目标

我的目标是在通过终端操作URL字符串中的值后直接访问该JSON文件。例如,如果我想在URL的这一部分中将哈希值从100更改为150:

[sha256_hr]=100& ---> [sha256_hr]=150&

在URL操作之后(如上所述,但不限于此),我希望收到JSON输出,以便我可以选择所需的数据。

My Code

咨询:我开始编程〜2017年6月,请原谅。

import json
import pandas as pd
import urllib2
import requests


hashrate_ghs = float(raw_input('Hash Rate (TH/s): '))
power_W = float(raw_input('Power of Miner (W): '))
electric_cost = float(raw_input('Cost of Power ($/kWh): '))
hashrate_ths = hashrate_ghs * 1000

initial_request = ('https://whattomine.com/asic?utf8=%E2%9C%93&sha256f=true&factor[sha256_hr]={0}&factor[sha256_p]={1}&factor[cost]={2}&sort=Profitability24&volume=0&revenue=24h&factor[exchanges][]=&factor[exchanges][]=bittrex&dataset=Main&commit=Calculate'.format(hashrate_ths, power_W, electric_cost))
data_stream_mine = urllib2.Request(initial_request)

json_data = requests.get('https://whattomine.com/asic.json')
print json_data

Error from My Code

我收到HTTPS握手错误。这是我的Python新鲜度第二最明显可见的地方:

Traceback (most recent call last):
  File "calc_1.py", line 16, in <module>
    s.get('https://whattomine.com/asic.json')
  File "/Library/Python/2.7/site-packages/requests/sessions.py", line 521, in get
    return self.request('GET', url, **kwargs)
  File "/Library/Python/2.7/site-packages/requests/sessions.py", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "/Library/Python/2.7/site-packages/requests/sessions.py", line 618, in send
    r = adapter.send(request, **kwargs)
  File "/Library/Python/2.7/site-packages/requests/adapters.py", line 506, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='whattomine.com', port=443): Max retries exceeded with url: /asic.json (Caused by SSLError(SSLError(1, u'[SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:590)'),))

谢谢你的帮助和时间!

如有任何变更或有关此问题的更多信息,请告知我。

json python-2.7 pandas python-requests urllib2
2个回答
1
投票

这只是一个评论。以下方法就足够了(Python 3)。

import requests

initial_request = 'http://whattomine.com/asic.json?utf8=1&dataset=Main&commit=Calculate'

json_data = requests.get(initial_request)
print(json_data.json())

这一部分的关键点 - 将.json放在你的initial_request中就足够了。您可以像在? sign之后在查询部分中那样添加所有参数


1
投票

看起来其他几个人面临类似的问题。

虽然对某些人来说,它似乎像一个pyOpenSSL version issue,卸载和重新安装,这解决了问题。 SO的另一个老答案问do the following

© www.soinside.com 2019 - 2024. All rights reserved.