Created
February 22, 2014 14:20
-
-
Save zonble/9155540 to your computer and use it in GitHub Desktop.
斧頭幫第一關 http://axe.g0v.tw/level/1
This file contains hidden or 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 | |
| # encoding: utf-8 | |
| # http://axe.g0v.tw/level/1 | |
| import urllib, urllib2, re | |
| html = urllib2.urlopen("http://axe-level-1.herokuapp.com").read() | |
| pattern = r"<tr>\s*<td>(.*)</td>\s*<td>(.*)</td>\s*<td>(.*)</td>\s*<td>(.*)</td>\s*<td>(.*)</td>\s*<td>(.*)</td>\s*</tr>" | |
| result = re.findall(pattern, html, re.MULTILINE) | |
| line = u'{"name": "%s", "grades": {"國語": %s, "數學": %s, "自然": %s, "社會": %s, "健康教育": %s}}' | |
| result = [line % tuple([s.decode('utf-8') for s in x]) for x in result[1:]] | |
| json_text = "[%s]" % ",\n".join(result) | |
| print json_text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment