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

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
my-lord
Posts: 45
Joined: 01 Apr 2018, 15:12

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

19 Apr 2018, 05:24

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.
User avatar
tank
Posts: 3122
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

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

19 Apr 2018, 09:50

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()
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
my-lord
Posts: 45
Joined: 01 Apr 2018, 15:12

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

21 Apr 2018, 07:22

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
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

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

21 Apr 2018, 08:28

unlearn traditional syntax

Code: Select all

google := "https://www.google.com/search?tbm=vid&hl=en-TR&source=hp&biw=&bih=&q=" . Clipboard
my-lord
Posts: 45
Joined: 01 Apr 2018, 15:12

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

21 Apr 2018, 08:46

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:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], mikeyww, ulysim and 324 guests