Hello, folks,
i am currently experimenting with the HTTP lib in Julia and try to evaluate the youtube search suggestions.
It also works as far as I want to get more search suggestions and not just the first 20. What is the best way to do that?
At the moment i do something like this -
using HTTP
function getPositions(search::String, txt::String)
vpos=UnitRange{Int32}[]
i=1
while ((pos=findnext(search, txt, i)) != nothing)
push!(vpos, pos)
i=pos[end]+1
end
return vpos
end
function getPositions(search::String, txt::String, vec::Vector{UnitRange{Int32}})
vpos=UnitRange{Int32}[]
for v in vec
pos=findnext(search, txt, v[end]+1)
(pos != nothing) && push!(vpos, pos)
end
return vpos
end
function posText(vRange::Vector{UnitRange{Int32}}, txt::String)
vpos=UnitRange{Int32}[]
for range in vRange
if ((pos=findnext("\"", txt, range[end]+1)) != nothing)
r=range[end]+1:pos[end]-1
push!(vpos, r)
end
end
return vpos
end
r = HTTP.request("GET", "https://www.youtube.com/results?search_query=julia+programming")
println("Status : ", r.status)
txt = String(r.body)
open("youtube.txt", "w") do io
print(io, txt)
end
v=getPositions("div class=\"yt-lockup-content",txt)
vt=getPositions("title=\"", txt, v)
vt=posText(vt, txt)
vhref=getPositions("a href=\"", txt, v)
vhref=posText(vhref, txt)
for (n, pos) in enumerate(vhref)
playLink="https://www.youtube.com" * txt[pos]
linkText=txt[vt[n]]
println("($n) : $linkText")
println("($n) : $playLink")
end
this gives me all the html and scipts which i parse through to search for the titles and the video-links. I don’t know much about webdesign and javascript, but is there a link i overseen to the next search suggestions?
best regards
Michael