-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCryptoWeb.py
More file actions
55 lines (54 loc) · 1.45 KB
/
Copy pathCryptoWeb.py
File metadata and controls
55 lines (54 loc) · 1.45 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from bs4 import BeautifulSoup
import requests , sys
def formatter(data):# formats the data
chars = list(data)
result = ""
newLine = True
dollars = 0
for char in chars:
if char=='%':
result += "%\n"
newLine = True # prints new lines
elif char=='$':
result += ";$" # seperates money values
dollars += 1
else:
if newLine==True:
result += char+">"
newLine = False # adds > after index position
elif dollars==3 and char==' ':
result += " ;"# adds semi-colon before value
dollars = 0
else:
result += char
return result
def collector():
url = "https://coinmarketcap.com/"
try:
resp = requests.get(url)
soup = BeautifulSoup(resp.text,"html.parser")
fields = soup.findAll("tr")
return fields
except ConnectionError:
print("Connection to target site failed: Please check your internet connection")
except Exception as e:
print(f"An exception of type {e} occured !")
sys.exit()
return False
def organizer():
count = 3
aggregator = ""
fields = collector()
if fields==False:
print("Please try again after fixing network issues.")
sys.exit()
for field in fields:
if count==0:
aggregator += field.text
else:
count -= 1
# available fields on webpage name, market cap , price, volume(24h) , circulating supply , change(24h) , price graph
with open("cryptoWeb.txt","w") as fl:
fl.write(formatter(aggregator))
if __name__=='__main__':
organizer()