Hi guys i am having this weird issue where this empty space appears even so after calling the strip() build in python program.
Here is the code i have been working on lately
Output
The empty space appears on the price example
$9,182.77
+$21.09
(+0.23%)
What i think is that i am not calling the right class element or maybe i simply call and not align it what might be the wrong thing i am doing in this code.
Ok i think i might have solved the issue by replacing it
One thing left is that can i keep this program running on the terminal and see the price change's in real time using the terminal how can i accomplish this in python
Here is the code i have been working on lately
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
#create a simple script that will visit the website and check out the btc price in real time from bs4 import BeautifulSoup import requests content1 = requestbtc.content content2 = requestseth.content soup1 = BeautifulSoup(content1, "html.parser" ) soup2 = BeautifulSoup(content2, "html.parser" ) element1 = soup1.find( 'div' ,{ "class" : "header-price-container" }) btc = element1.text.strip() element2 = soup2.find( 'div' ,{ "class" : "header-price-container" }) eth = element2.text.strip() print ( "-------------BTC Price------------" ) print (btc) print ( "\n" ) print ( "-------------ETH Price------------" ) print (eth) print ( "\n" ) #The Html elements are same for both # <div class="header-price-container"> # <div class="header-price-main"> # <span style="background: inherit; padding: 0px 1px;"> # <span style="color: inherit;">$206.5</span> # <span style="color: inherit;">4</span> # </span> # </div> # <div class="header-price-sub"> # <span style="color: rgb(0, 153, 51);">+$4.3349 </span> # <span style="color: rgb(0, 153, 51);">(+2.14%)</span> # </div> # </div> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
>python btc.py - - - - - - - - - - - - - BTC Price - - - - - - - - - - - - $ 9 , 182.77 + $ 21.09 ( + 0.23 % ) - - - - - - - - - - - - - ETH Price - - - - - - - - - - - - $ 207.36 + $ 4.2616 ( + 2.10 % ) |
$9,182.77
+$21.09
(+0.23%)
What i think is that i am not calling the right class element or maybe i simply call and not align it what might be the wrong thing i am doing in this code.
Ok i think i might have solved the issue by replacing it
1 2 3 4 5 6 7 |
element1 = soup1.find( 'div' ,{ "class" : "header-price-container" }) btc = element1.text.strip() btc = btc.replace( '\n' , ' \t ' ) element2 = soup2.find( 'div' ,{ "class" : "header-price-container" }) eth = element2.text.strip() eth = eth.replace( '\n' , ' \t ' ) |