-
-
Notifications
You must be signed in to change notification settings - Fork 311
Expand file tree
/
Copy pathparsebanks.py
More file actions
27 lines (21 loc) · 676 Bytes
/
Copy pathparsebanks.py
File metadata and controls
27 lines (21 loc) · 676 Bytes
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
from bs4 import BeautifulSoup
import urllib2
import json
ALI_BANKS = 'http://ab.alipay.com/i/yinhang.htm'
try:
response = urllib2.urlopen(ALI_BANKS)
except urllib2.HTTPError, e:
print "HTTP Error %s : %s" % (e.code, e.reason)
system.exit(1)
except urllib2.URLError, e:
print "Unable to connect the remote server."
system.exit(1)
content = response.read()
soup = BeautifulSoup(content)
spans = soup.find_all("span", class_="icon")
# banks = {}
# for span in spans:
# banks[span['class'][1]] = span.text
banks = { span['class'][1] : span.text for span in spans }
print json.dumps(banks, ensure_ascii=False, indent=2)
print "total : %d" % len(banks)