Web-scraping from Coinbase with Python Pycharm

0 votes

I am trying to write some code that will give me the price in BTC when I run it. I am not getting the price and I am getting NONE. Can anyone look at my code and figure out what the problem is? Here is the code below:

import requests
from bs4 import BeautifulSoup

page = requests.get("https://www.coinbase.com/charts")
soup = BeautifulSoup(page.content, 'html.parser')
seven_day = soup.find(id="seven-day-forecast")
bitcoin = soup.find('pre',{'style':'word-wrap: break-word; white-space: pre-
wrap;'})

print(bitcoin)
Sep 4, 2018 in Blockchain by slayer
• 29,300 points

retagged Nov 22, 2018 by Kalgi 1,534 views

1 answer to this question.

0 votes

Data that you want to scrape is dynamically generated. You can make direct request to API to get those values:

url = 'https://api.coinbase.com/v2/prices/USD/spot?'
response = requests.get(url).json()
print(response)

Output:

{'data': [{'currency': 'USD', 'base': 'BTC', 'amount': '7590.01'}, {'currency':
'USD', 'base': 'ETH', 'amount': '296.86'}, {'currency': 'USD', 'base': 'LTC', 'amount': '54.59'}]}

To get required value:

print(response['data'][0]['amount'])

Output:

'7590.01'
answered Sep 4, 2018 by digger
• 26,700 points

Related Questions In Blockchain

0 votes
1 answer

How to interact with blockchain from web application?

You can use the Web3.js library to interact ...READ MORE

answered Jan 11, 2019 in Blockchain by Omkar
• 69,130 points
361 views
0 votes
1 answer
0 votes
1 answer

How to download the full blocks (with transactions) directly and in parallel from the connected nodes in NodesGroup?

 just got informed, that NBitcoin currently does ...READ MORE

answered Jul 31, 2018 in Blockchain by Shashank
• 10,400 points
115 views
0 votes
1 answer
0 votes
1 answer

Python request module for bitcoin json rpc

This should work: #!/usr/bin/env python import getpass import json import requests ...READ MORE

answered Aug 28, 2018 in Blockchain by digger
• 26,700 points
1,028 views
0 votes
1 answer

Cant locate english.txt file while intalling Python Bitcoin module

This is related to a pybitcointools bug where the ...READ MORE

answered Aug 30, 2018 in Blockchain by slayer
• 29,300 points
210 views
0 votes
1 answer
0 votes
1 answer

How to interact with blockchain using Java web app?

You can interact with the blockchain using ...READ MORE

answered Jul 16, 2018 in Blockchain by digger
• 26,700 points
515 views
0 votes
1 answer

How to achieve consensus with peers from different departments?

Defining one MSP to represent each division. ...READ MORE

answered Jul 16, 2018 in Blockchain by digger
• 26,700 points
176 views