Skip to content

Instantly share code, notes, and snippets.

@zonble
Created February 24, 2014 15:56
Show Gist options
  • Select an option

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

Select an option

Save zonble/9191000 to your computer and use it in GitHub Desktop.
斧頭幫第二關 Julia 版本
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