我已经编写了一些代码来从投资网站上抓取 BTC/ETH 时间序列,并且运行良好。但是,我需要更改请求调用,以便下载的数据来自 Kraken 而不是默认的 bitfinex 并且来自 01/06/2016 而不是默认的开始时间。这个选项可以在网页上手动设置,但我不知道如何通过请求调用发送它,除了它可能涉及使用“数据”参数。感谢任何建议。
谢谢,
知识管理
代码已经用 python 编写并且适用于默认值
import requests
from bs4 import BeautifulSoup
import os
import numpy as np
# BTC scrape https://www.investing.com/crypto/bitcoin/btc-usd-historical-data
# ETH scrape https://www.investing.com/crypto/ethereum/eth-usd-historical-data
ticker_list = [x.strip() for x in open("F:\\System\\PVWAVE\\Crypto\\tickers.txt", "r").readlines()]
urlheader = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36",
"X-Requested-With": "XMLHttpRequest"
}
print("Number of tickers: ", len(ticker_list))
for ticker in ticker_list:
print(ticker)
url = "https://www.investing.com/crypto/"+ticker+"-historical-data"
req = requests.get(url, headers=urlheader, data=payload)
soup = BeautifulSoup(req.content, "lxml")
table = soup.find('table', id="curr_table")
split_rows = table.find_all("tr")
newticker=ticker.replace('/','\\')
output_filename = "F:\\System\\PVWAVE\\Crypto\\{0}.csv".format(newticker)
os.makedirs(os.path.dirname(output_filename), exist_ok=True)
output_file = open(output_filename, 'w')
header_list = split_rows[0:1]
split_rows_rev = split_rows[:0:-1]
for row in header_list:
columns = list(row.stripped_strings)
columns = [column.replace(',','') for column in columns]
if len(columns) == 7:
output_file.write("{0}, {1}, {2}, {3}, {4}, {5}, {6} \n".format(columns[0], columns[2], columns[3], columns[4], columns[1], columns[5], columns[6]))
为默认交换和默认日期范围下载数据,但我想指定 Kraken 和默认开始和结束时间(01/06/16 和最后一整天,即总是昨天)
繁星coding
相关分类