Page 1 of 1

How can I retrieve first youtube url from google video search results?

Posted: 19 Apr 2018, 05:24
by my-lord
I want to retrieve the first URL from google video search results.
I can do it with Java in the following way:

Code: Select all

    public static String getYoutubeURLByName(String search) throws UnsupportedEncodingException, MalformedURLException, MalformedURLException, MalformedURLException, MalformedURLException, IOException {
            String google = "https://www.google.com/search?tbm=vid&hl=en-TR&source=hp&biw=&bih=&q=";
            String charset = "UTF-8";
            String userAgent = "Mozilla/5.0"; 
    
            Elements links = Jsoup.connect(google + URLEncoder.encode(search, charset)).userAgent(userAgent).get().select(".g .r a");
            String url = links.get(0).absUrl("href");
            url = URLDecoder.decode(url.substring(url.indexOf('=') + 1, url.indexOf('&')), "UTF-8");
            System.out.println(url);
            return url;
        }

But I don't know how can I retrieve the first youtube URL from google video search results in AutoHotkey.

Re: How can I retrieve first youtube url from google video search results?  Topic is solved

Posted: 19 Apr 2018, 09:50
by tank

Code: Select all

search := "jolene"
google := "https://www.google.com/search?tbm=vid&hl=en-TR&source=hp&biw=&bih=&q="
(pwb := ComObjCreate("InternetExplorer.Application")).Visible:=True
pwb.navigate(google search)
while pwb.busy
	sleep 15
msgbox % pwb.document.querySelectorAll("#ires a")[0].href
pwb.quit()

Re: How can I retrieve first youtube url from google video search results?

Posted: 21 Apr 2018, 07:22
by my-lord
tank wrote:

Code: Select all

search := "jolene"
google := "https://www.google.com/search?tbm=vid&hl=en-TR&source=hp&biw=&bih=&q="
(pwb := ComObjCreate("InternetExplorer.Application")).Visible:=True
pwb.navigate(google search)
while pwb.busy
	sleep 15
msgbox % pwb.document.querySelectorAll("#ires a")[0].href
pwb.quit()
Thanks.But my script ended with a wrong URL on my browser "http://%22https//www.google.com/search?tbm... "
I tried to fix with StrReplace function like this but It didn't work.
pwb.navigate(StrReplace(google,"http://%22",""))
How can I fix that?

Code: Select all

^+K::
Send ^c
sleep 50
google= "https://www.google.com/search?tbm=vid&hl=en-TR&source=hp&biw=&bih=&q=%clipboard%"
(pwb := ComObjCreate("InternetExplorer.Application")).Visible:=False
pwb.navigate(StrReplace(google,"http://%22",""))
while pwb.busy
	sleep 15
msgbox % pwb.document.querySelectorAll("#ires a")[0].href
pwb.quit()
Return

Re: How can I retrieve first youtube url from google video search results?

Posted: 21 Apr 2018, 08:28
by swagfag
unlearn traditional syntax

Code: Select all

google := "https://www.google.com/search?tbm=vid&hl=en-TR&source=hp&biw=&bih=&q=" . Clipboard

Re: How can I retrieve first youtube url from google video search results?

Posted: 21 Apr 2018, 08:46
by my-lord
swagfag wrote:unlearn traditional syntax

Code: Select all

google := "https://www.google.com/search?tbm=vid&hl=en-TR&source=hp&biw=&bih=&q=" . Clipboard
Thanks,It works :superhappy: