CoinGecko服务有一个Python包装器,可以像这样连接:
from pycoingecko import CoinGeckoAPI
cg = CoinGeckoAPI()
price = cg.get_coin_by_id('tether')我有一个python代码,它解析а空闲代理站点并返回随机代理dict,如{'https':'187.62.191.3:61256'}
import requests
from bs4 import BeautifulSoup
from random import choice
def get_proxy():
url = "https://www.ssl-site.com/"
r = requests.get(url)
soup = BeautifulSoup(r.content, 'html5lib')
return{'https': choice(list(map(lambda x:x[0]+':'+x[1], list(zip(map(lambda x:x.text, soup.findAll('td')[::8]), map(lambda x:x.text, soup.findAll('td')[1::8]))))))}
get_proxy()
def proxy_request(request_type, url, **kwargs):
while 1:
try:
proxy = get_proxy()
print('Using proxy: {}'.format(proxy))
r = requests.request(request_type, url, proxies=proxy, timeout=5, **kwargs)
break
except:
pass
return r如何每次从新ip调用CoinGecko API包装终结点?
发布于 2022-11-04 13:20:37
您可以在直接使用session属性初始化CoinGeckoAPI()之后设置代理,然后调用任何API端点。例如:
import pycoingecko
cg=pycoingecko.CoinGeckoAPI()
# set up a proxy (or any other dictionary with proxies)
cg.session.proxies['https']='http://10.10.1.10:1080'
# you can check proxies by printing them
print(cg.session.proxies)
# output here should be: {'https': 'http://10.10.1.10:1080'}
# call an endpoint, for example get price of bitcoin in USD
cg.get_price(ids='bitcoin', vs_currencies='usd')https://stackoverflow.com/questions/70783198
复制相似问题