-
Notifications
You must be signed in to change notification settings - Fork 0
/
crawl.py
78 lines (68 loc) · 2.16 KB
/
crawl.py
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from bs4 import BeautifulSoup
import sys
from re import sub
from decimal import Decimal
import datetime
from dateutil import parser
from model import TokenTransaction
from urllib.request import build_opener
import multiprocessing
def get_html_by_url(url):
opener = build_opener()
opener.addheaders = [('User-Agent', 'Mozilla/5.0')]
response = opener.open(url)
html = response.read()
soup = BeautifulSoup(html)
return soup
def get_transcripts_at_p(token_name,p):
base_url = 'https://etherscan.io/token/generic-tokentxns2?contractAddress=0xe41d2489571d322189246dafa5ebde1f4699f498&p={}'.format(p)
soup = get_html_by_url(base_url)
arrs = soup.findAll('tr')
transactions = []
for x in range(1,len(arrs)):
arr = arrs[x]
tds = arr.findAll('td')
txhash = ""
timestamp = ""
from_account = ""
to_account = ""
quantity = ""
for y in range(0,len(tds)):
td = tds[y]
if y == 0:
#txhash
txhash = td.text
elif y == 1:
#timestamp
timestamp = td.find("span")["title"]
timestamp = parser.parse(timestamp)
elif y == 2:
#from
from_account = td.find("span").find('a').text
elif y == 4:
# to
to_account = td.find("span").find("a").text
elif y == 5:
# quantity
quantity = td.text
token_transaction = TokenTransaction(token_name,txhash,timestamp,from_account,to_account,quantity)
transactions.append(token_transaction)
return transactions
def write_to_csv(transactions):
csvoutput = open("0x_last_few_pages.csv","a")
for t in transactions:
csvoutput.write("{},{},{},{},{},{}\n".format(t.token_name,t.tx_hash,t.timestamp,t.from_account,t.to_account,t.quantity))
csvoutput.close()
# add header
csvoutput = open("0x_last_few_pages.csv","w+")
csvoutput.write("Token_Name,txhash,timestamp,from_account,to_account,quantity\n")
csvoutput.close()
first_page = 2600
last_page = 2612
for x in range(first_page,last_page+1):
print(x)
transactions = get_transcripts_at_p("0x",x)
write_to_csv(transactions)
#transactions = get_transcripts_at_p("0x",49)
#for t in transactions:
# print(t.quantity)