简体   繁体   English

使用Python进行网页(Coinbase)数据抓取

[英]Webpage (Coinbase) data Scraping using Python

I am a noob in Python and am currently in the process of trying to write some code that when I run it, will give me the price of bitcoin from Coinbase. 我是Python的新手,目前正在尝试编写一些代码,这些代码在我运行时会给我Coinbase的比特币价格。 Whenever I run the code, it says none instead of the price of Bitcoin. 每当我运行代码时,它都说没有,而不是比特币的价格。

Below is my code: 下面是我的代码:

import requests
from bs4 import BeautifulSoup

page = requests.get('https://www.coinbase.com/dashboard')
soup = BeautifulSoup(page.content, 'lxml')

price = soup.find(id='id root')
assert isinstance(price, object)
bitcoin = soup.find('span',{'class':'BigAmount__AmountSuper-jnVzGG jdlzFZ'})

print(bitcoin)

Coinbase needs you to login before showing the dashboard. Coinbase需要您登录才能显示仪表板。 It works in your browser because you've already logged in, so you will be directed to dashboard. 它已经在您的浏览器中工作,因为您已经登录,因此将您定向到仪表板。

You can use https://www.coinbase.com/charts and class PriceChart__HeadingPrice-iOthZP gLGtWx Flex__Flex-fVJVYW iDqRrV to extract the Bitcoin price. 您可以使用https://www.coinbase.com/charts并使用PriceChart__HeadingPrice-iOthZP gLGtWx Flex__Flex-fVJVYW iDqRrV来提取比特币价格。

You can also use https://min-api.cryptocompare.com/data/pricemulti?fsyms=BTC&tsyms=USD,EUR,INR to fetch bitcoin price in other currencies as well.. 您还可以使用https://min-api.cryptocompare.com/data/pricemulti?fsyms=BTC&tsyms=USD,EUR,INR来获取其他货币的比特币价格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM