Created
February 24, 2014 15:23
-
-
Save zonble/9190300 to your computer and use it in GitHub Desktop.
斧頭幫第一關 Julia 版本
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
| using HTTPClient.HTTPC | |
| r = HTTPC.get("http://axe-level-1.herokuapp.com") | |
| @assert r.http_code == 200 | |
| html = bytestring(r.body) | |
| pattern = r"<tr>\s*<td>(.*)</td>\s*<td>(.*)</td>\s*<td>(.*)</td>\s*<td>(.*)</td>\s*<td>(.*)</td>\s*<td>(.*)</td>\s*</tr>" | |
| substrings = matchall(pattern, html) | |
| lines = String[] | |
| for s in substrings[2:] | |
| c = match(pattern, s).captures | |
| push!(lines, "{\"name\": \"$(c[1])\", \"grades\": {\"國語\": $(c[2]), \"數學\": $(c[3]), \"自然\": $(c[4]), \"社會\": $(c[5]), \"健康教育\": $(c[6])}}") | |
| end | |
| f = open("test.txt", "w") | |
| write(f, "[$(join(lines, ","))]") | |
| close(f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment