Last active
April 8, 2019 17:56
-
-
Save hpoit/7c6ce575fc5a4a274ed8c9cb6eab4a19 to your computer and use it in GitHub Desktop.
Cascadia.jl working webscraping example
This file contains 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
# https://github.com/Algocircle/Cascadia.jl#webscraping-example | |
using Cascadia | |
using Gumbo | |
using HTTP | |
# using Requests (deprecated) | |
r = HTTP.get("http://stackoverflow.com/questions/tagged/julia-lang") | |
h = parsehtml(String(r.body)) | |
qs = eachmatch(Selector(".question-summary"), h.root) | |
println("StackOverflow Julia Questions (votes answered? url)") | |
for q in qs | |
votes = nodeText(eachmatch(Selector(".votes .vote-count-post "), q)[1]) | |
answered = length(eachmatch(Selector(".status.answered"), q)) > 0 | |
href = eachmatch(Selector(".question-hyperlink"), q)[1].attributes["href"] | |
println("$votes $answered http://stackoverflow.com$href") | |
end | |
using JSON | |
JSON.json(qs) # returns StackOverflowError |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment