File tree 1 file changed +36
-0
lines changed
WebScrapingScripts/crypto_price_checker
1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ import requests
2
+ import bs4
3
+
4
+ url = "https://www.cointracker.io/price"
5
+ req = requests .get (url )
6
+ scrap = bs4 .BeautifulSoup (req .text , 'html.parser' )
7
+
8
+ #getting list of individual sites to get price data
9
+ individual_sites = [tag ['href' ] for tag in scrap .find_all ('a' , {'class' :"d-flex no-underline" })]
10
+
11
+ for i in range (len (individual_sites )):
12
+ #appending the string for each "i" to "https://www.cointracker.io".
13
+ url2 = "https://www.cointracker.io" + individual_sites [i ]
14
+ req2 = requests .get (url2 )
15
+ scrap2 = bs4 .BeautifulSoup (req2 .text , 'html.parser' )
16
+
17
+ #getting the cryptocurreny name from the string
18
+ crypto_name = individual_sites [i ][7 :]
19
+
20
+ #getting the data where the price is present and converting it to string
21
+ findClass = scrap2 .find ('div' , {'class' :'my-auto h4' })
22
+ findClassStr = str (findClass )
23
+
24
+ #finding index from which price of cryptocurrency starts
25
+ idx = findClassStr .find ("data-price-container-symbol=" )
26
+ idx = findClassStr .find (">" , idx , len (findClassStr ))
27
+ idx = idx + 1
28
+ price_str = ""
29
+
30
+ #looping till I get the complete price as a string
31
+ while (findClassStr [idx ]!= "<" ):
32
+ price_str = price_str + findClassStr [idx ]
33
+ idx = idx + 1
34
+ print ("crptocurrency : " + crypto_name + " and 1 " + crypto_name + " = " + price_str )
35
+
36
+
You can’t perform that action at this time.
0 commit comments