Skip to content

Instantly share code, notes, and snippets.

@zonble
Created February 24, 2014 16:36
Show Gist options
  • Select an option

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

Select an option

Save zonble/9191751 to your computer and use it in GitHub Desktop.
斧頭幫第三關 Julia 版本
using HTTPClient.HTTPC
lines=String[]
cookie=""
url="http://axe-level-1.herokuapp.com/lv3/"
for index = [1:76]
if index == 1
r=HTTPC.get(url)
received_cookie=r.headers["Set-Cookie"]
cookie=received_cookie[1:search(received_cookie, ';')]
else
r=HTTPC.get(url * "?page=next", RequestOptions(headers=[("Cookie", cookie)]))
end
@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