-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoinmarketcapWebScraper.py
More file actions
executable file
·56 lines (44 loc) · 1.53 KB
/
Copy pathcoinmarketcapWebScraper.py
File metadata and controls
executable file
·56 lines (44 loc) · 1.53 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
56
from lxml import html
import requests
import json
import numpy as np
import operator
# coinmarketcap api
#warning this must be updated everyday
coinmarketcapWebPage = requests.get("https://coinmarketcap.com/currencies/neo/historical-data/?start=20170721&end=20170727")
# We need to use page.content rather than page.text
# because html.fromstring implicitly expects bytes as input.
tree = html.fromstring(coinmarketcapWebPage.content)
# webData is every text in the td divs
webData = tree.xpath('//td/text()')
# separating the data into variables
date = webData[0::7]
dateOpen = webData[1::7]
dateHigh = webData[2::7]
dateLow = webData[3::7]
dateClose = webData[4::7]
dateVolume = webData[5::7]
dateMarketCap = webData[6::7]
firstFiveHigh = dateHigh[:3]
firstFiveLow = dateLow[:3]
avgHigh = [float(numeric_string) for numeric_string in firstFiveHigh]
avgLow = [float(numeric_string) for numeric_string in firstFiveLow]
realAvgHigh = sum(avgHigh)/len(avgHigh)
realAvgLow = sum(avgLow)/len(avgLow)
print(realAvgHigh)
print(realAvgLow)
# print(np.mean(firstTen))
# averageLow = sum(float(int(str(firstTen))))
# print(averageLow)
# print('dates ', date)
# print('open', dateOpen)
# print('high', dateHigh)
# print('low', dateLow)
# print('close', dateClose)
# print('Volume', dateVolume)
# print('MarketCap', dateMarketCap)
# print(averageLow)
# print('Data for coin: ', data)
# print(r.text)
# jsonCleaned = json.dumps(data, indent=4, sort_keys=True)
# print(json.dumps(data, indent=4, sort_keys=True))