Created
February 24, 2014 15:56
-
-
Save zonble/9191000 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 | |
| lines = String[] | |
| for index =[1:13] | |
| url = "http://axe-level-1.herokuapp.com/lv2" | |
| r = HTTPC.get(url, RequestOptions(query_params=collect({:page => index}))) | |
| @assert r.http_code == 200 | |
| html = bytestring(r.body) | |
| pattern = r"<tr>\s*<td>(.*)</td>\s*<td>(.*)</td>\s*<td>(.*)</td>\s*</tr>" | |
| substrings = matchall(pattern, html) | |
| for s in substrings[2:] | |
| c = match(pattern, s).captures | |
| push!(lines, "{\"town\": \"$(c[1])\", \"village\": \"$(c[2])\", \"name\" : \"$(c[3])\"}") | |
| end | |
| 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