2017-11-05 3 views
0

나는 그것을 실행할 때 BTC에 가격을 줄 일부 코드를 작성하려고합니다. 나는 이 아니지만 코드를 실행 한 후 오류가 발생하는이 아닙니다. 나는 가격을 얻지 못하고 있습니다. NONE. 누구든지 내 코드를보고 문제가 무엇인지 파악할 수 있습니까? 아래 코드는 다음과 같습니다.Python (Pycharm)과 Coinbase에서 웹 스크래핑

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) 

감사합니다.

+0

'document.getElementById ("seven-day-forecast") = null " – TheChetan

답변

1

스크래핑하려는 데이터가 dinamycally 생성됩니다.

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

출력 :

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

이 필요 얻을 수있는 값 :

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

출력 :

'7590.01' 
당신은 그 값을 얻기 위해 API에 직접 요청을 할 수 있습니다
+0

@Jay, 피드백이 있습니까? – Andersson