Skip to content

Instantly share code, notes, and snippets.

@zonble
Created February 22, 2014 14:20
Show Gist options
  • Select an option

  • Save zonble/9155540 to your computer and use it in GitHub Desktop.

Select an option

Save zonble/9155540 to your computer and use it in GitHub Desktop.
斧頭幫第一關 http://axe.g0v.tw/level/1
#!/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