Skip to content

Commit a7b7e83

Browse files
authored
Merge pull request #192 from TaniaMalhotra/bitcoin-price
Bitcoin price
2 parents db83e46 + 9083ee1 commit a7b7e83

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

Python/bitcoin-price/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Script to get current bitcoin price
2+
- - - - - - - - - - - -
3+
## Aim
4+
Aim of the script is to get the current price of bitcoin using python.
5+
6+
## Approach
7+
The approach followed here is the use of bs4 for scraping. We open the coinmarketcap current price page, locate the div and extract the span element containing the price.</br>
8+
9+
## Requirements
10+
11+
```pip install bs4```</br>
12+
13+
```pip install requests```</br>
14+
15+
## To run
16+
17+
```python current_price.py```

Python/bitcoin-price/current_price.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import requests
2+
from bs4 import BeautifulSoup as BS
3+
4+
# We are basically getting the URL of coinmarket camp and scraping it's content
5+
soup = BS(requests.get('https://coinmarketcap.com/currencies/bitcoin/').content, features="lxml")
6+
7+
# Here we are searching for the corresponding div in which span class is present
8+
# then we need to extract the span class
9+
div = soup.find("div", {"class" : "f6l7tu-0 cdygDb cmc-details-panel-price"
10+
}).find("span", {"class" : "cmc-details-panel-price__price"})
11+
12+
# Now we print all elements extracted from div
13+
for i in div:
14+
print(i)

Python/bitcoin-price/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
beautifulsoup4==4.9.1
3+
requests==2.24.0

0 commit comments

Comments
 (0)