Last active
January 11, 2019 05:58
-
-
Save wenweih/1cac6afabba7bd0b67aa32dcfcd480b5 to your computer and use it in GitHub Desktop.
Query top accounts from Etherscan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import requests | |
from bs4 import BeautifulSoup | |
import csv | |
def dump(soup): | |
table = soup.find_all("div", class_="table-responsive") | |
for t in table: | |
for tr in t.find_all('tr'): | |
tds = tr.find_all('td') | |
rows = [0] * len(tds) | |
for i in range(len(tds)): | |
rows[i] = tds[i].get_text() | |
if i == 1: | |
isContract = tds[i].find("i") | |
if isContract is not None: | |
rows[i] = "contract account" | |
else: | |
rows[i] = 'normal account' | |
try: | |
writer.writerow({'Rank': rows[0], | |
'Type': rows[1], | |
'Address': rows[2], | |
'Belong': rows[3], | |
'Balance': rows[4], | |
'Percentage': rows[5], | |
'TxCount': rows[6] | |
}) | |
print("Rank: " + rows[0] + " Address: ", rows[2]) | |
except: | |
pass | |
with open('ethereum_top_accounts.csv', 'w') as f: | |
fieldnames = ['Rank', 'Type', 'Address', 'Belong', 'Balance', 'Percentage', 'TxCount'] | |
writer = csv.DictWriter(f, fieldnames=fieldnames) | |
writer.writeheader() | |
for page in range (1, 101): | |
URL = "https://etherscan.io/accounts/" + str(page) + "?ps=100" | |
sess = requests.Session() | |
soup = BeautifulSoup(sess.get(URL).text, 'html.parser') | |
rows = dump(soup) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment