我正在尝试解析比特币的历史数据。我没有在30行中获得30分,而是重复了30天。
import requests
import urllib.request
from bs4 import BeautifulSoup
url = "https://coinmarketcap.com/currencies/bitcoin/historical-data/"
r = requests.get(url)
html_content = r.text
soup = BeautifulSoup(html_content,"html.parser")
for tr in soup.find_all('tr')[6]:
tds = soup.find_all('td')
print ("date: %s, Open: %s, High:%s, Low: %s, Close: %s, Volume: %s, Marketcap: %s\n" % \
(tds[0].text,tds[1].text,tds[2].text,tds[3].text,tds[4].text, tds[5].text, tds[6].text))
这是输出:
date: May 29, 2018, Open: 7129.46, High:7526.42, Low: 7090.68, Close: 7472.59, Volume: 5,662,660,000, Marketcap: 121,636,000,000
date: May 29, 2018, Open: 7129.46, High:7526.42, Low: 7090.68, Close: 7472.59, Volume: 5,662,660,000, Marketcap: 121,636,000,000
date: May 29, 2018, Open: 7129.46, High:7526.42, Low: 7090.68, Close: 7472.59, Volume: 5,662,660,000, Marketcap: 121,636,000,000
date: May 29, 2018, Open: 7129.46, High:7526.42, Low: 7090.68, Close: 7472.59, Volume: 5,662,660,000, Marketcap: 121,636,000,000
date: May 29, 2018, Open: 7129.46, High:7526.42, Low: 7090.68, Close: 7472.59, Volume: 5,662,660,000, Marketcap: 121,636,000,000
date: May 29, 2018, Open: 7129.46, High:7526.42, Low: 7090.68, Close: 7472.59, Volume: 5,662,660,000, Marketcap: 121,636,000,000
date: May 29, 2018, Open: 7129.46, High:7526.42, Low: 7090.68, Close: 7472.59, Volume: 5,662,660,000, Marketcap: 121,636,000,000
date: May 29, 2018, Open: 7129.46, High:7526.42, Low: 7090.68, Close: 7472.59, Volume: 5,662,660,000, Marketcap: 121,636,000,000
date: May 29, 2018, Open: 7129.46, High:7526.42, Low: 7090.68, Close: 7472.59, Volume: 5,662,660,000, Marketcap: 121,636,000,000
date: May 29, 2018, Open: 7129.46, High:7526.42, Low: 7090.68, Close: 7472.59, Volume: 5,662,660,000, Marketcap: 121,636,000,000
date: May 29, 2018, Open: 7129.46, High:7526.42, Low: 7090.68, Close: 7472.59, Volume: 5,662,660,000, Marketcap: 121,636,000,000
date: May 29, 2018, Open: 7129.46, High:7526.42, Low: 7090.68, Close: 7472.59, Volume: 5,662,660,000, Marketcap: 121,636,000,000
date: May 29, 2018, Open: 7129.46, High:7526.42, Low: 7090.68, Close: 7472.59, Volume: 5,662,660,000, Marketcap: 121,636,000,000
date: May 29, 2018, Open: 7129.46, High:7526.42, Low: 7090.68, Close: 7472.59, Volume: 5,662,660,000, Marketcap: 121,636,000,000
date: May 29, 2018, Open: 7129.46, High:7526.42, Low: 7090.68, Close: 7472.59, Volume: 5,662,660,000, Marketcap: 121,636,000,000
我应该获取4月30日 - 5月29日的日期数据
我错过了什么?