-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhpwn.py
executable file
·44 lines (38 loc) · 1.24 KB
/
hpwn.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
#!/usr/bin/env python
from __future__ import print_function
import os
import sys
import requests
import cfscrape
import pprint
from bs4 import BeautifulSoup
pp = pprint.PrettyPrinter(indent=4)
def get_cards_from_tables(tables):
cards = dict()
for table in tables:
for x in table.find_all('a'):
if x['href'].startswith('/cards/'):
count_str = x.parent.parent.contents[-1].strip()[-1]
card = x.contents[0]
count = int(count_str)
#print("%s x %d" % (card, count))
cards[card] = count
return cards
def url_to_decklist(url):
sess = requests.session()
sess = cfscrape.create_scraper(sess)
r = sess.get(url)
data = BeautifulSoup(r.content, "html.parser")
tbls = data.find_all('table', id="cards")
#print(tbl.prettify().encode('utf-8'))
decklist = get_cards_from_tables(tbls)
return decklist
def print_decklist(decklist):
for card, count in decklist.items():
print("%s x %d" % (card, count))
if __name__ == "__main__":
#url = 'http://www.hearthpwn.com/decks/276644-top-6-eu-loatheb-patron'
url = sys.argv[1].rstrip()
decklist = url_to_decklist(url)
#pp.pprint(decklist)
print_decklist(decklist)