【发布时间】:2020-12-30 21:56:55
【问题描述】:
我正在尝试从 coinmarketcap 的表格中抓取历史数据。但是,我运行的代码返回“没有数据”。我认为这会很容易,但不确定我错过了什么。
url = "https://coinmarketcap.com/currencies/bitcoin/historical-data/"
data = requests.get(url)
bs=BeautifulSoup(data.text, "lxml")
table_body=bs.find('tbody')
rows = table_body.find_all('tr')
for row in rows:
cols=row.find_all('td')
cols=[x.text.strip() for x in cols]
print(cols)
输出:
C:\Users\Ejer\anaconda3\envs\pythonProject\python.exe C:/Users/Ejer/PycharmProjects/pythonProject/CloudSQL_test.py
['No Data']
Process finished with exit code 0
【问题讨论】:
-
我发现了这个 xhr 请求,它似乎正在填充该表,所以我认为您不需要抓取:web-api.coinmarketcap.com/v1/cryptocurrency/ohlcv/…
-
你有一段代码在哪里使用它吗?
-
但是基本版好像不可用。好像想要历史数据就得花钱?
标签: python web-scraping beautifulsoup