Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- from urllib.request import Request, urlopen
- from bs4 import BeautifulSoup
- from collections import OrderedDict
- import sys
- #i.e. py blockScrapper.py etherscan.io
- URL = "https://"+sys.argv[1]+"/blocks_forked?ps=100&p="
- print(URL)
- def getData(sess, page):
- url = URL + page
- print("Retrieving page", page)
- #return BeautifulSoup(sess.get(url).text, 'html.parser')
- req = Request(url, headers={'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36'})
- response = urlopen(req, timeout=20).read()
- response_close = urlopen(req, timeout=20).close()
- return BeautifulSoup(response, "html.parser")
- def getPage(sess, page):
- table = getData(sess, str(page)).find("table", {"class": "table-hover"})
- rows = table.find('tbody').find_all('tr')
- columns =[X.text.strip() for X in table.find('thead').find_all('th')]
- index = columns.index('ReorgDepth')
- vals = [[X.text.strip() for X in row.find_all('td')][index+1] for row in rows]
- #print(vals)
- return vals
- def main():
- resp = requests.get(URL)
- sess = requests.Session()
- counts = OrderedDict()
- page = 0
- while True:
- page += 1
- try:
- data = getPage(sess, page)
- for item in data:
- if item in counts:
- counts[item] += 1
- else:
- counts[item] = 1
- except:
- break
- for k, v in counts.items():
- print("Forks of length {}: {}".format(k, v))
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement