How to open multiple urls. Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
hancre
Posts: 251
Joined: 02 Jul 2021, 20:51

How to open multiple urls.

29 Jan 2024, 01:38

I hope that selected urls would be opened automatically .

When I try this following script,
- the message box shows '1' for the numbers of urls
- run commands don't work.

How can I fix the issue?

test url :
https://www.autohotkey.com/
https://artelogic.net/blog/top-7-web-resources-built-using-net/
https://en.wikipedia.org/wiki/.edu

Code: Select all


#z::  { 
    url := "" 
    Send "^c"
    Sleep 50
    Loop parse A_Clipboard, "`n"
    {
        url :=RegExMatch(A_LoopField, "(\S+\.(com|net|co\.|biz|or|org|edu|kr|co\..+))")
        msgbox url  
        Run "chrome.exe" url
    }
}
User avatar
boiler
Posts: 17404
Joined: 21 Dec 2014, 02:44

Re: How to open multiple urls.

29 Jan 2024, 02:49

You don’t have a MsgBox that shows the number of URLs. And even if it did, why would you think it would be anything but 1 since you’re parsing it to a single line with each loop iteration? What do you think the parsing loop does?

Read the documentation for RegExMatch to understand what the return value is and how to get match string. If you know your list is a list of URLs, then I don’t see why you’re using RegExMatch anyway. What are you trying to accomplish with that line? Why wouldn’t you just do the following?

Code: Select all

#z:: { 
    Send "^c"
    ClipWait 1
    Loop parse A_Clipboard, "`n"
        Run "chrome.exe " A_LoopField
}
hancre
Posts: 251
Joined: 02 Jul 2021, 20:51

Re: How to open multiple urls.

29 Jan 2024, 20:57

@boiler

Ah. sorry. I forgot that there're letters and numbers, spcial charaters(ex", ?, :) in raw data.
I didn't add them in the test url in mistake.
ex. test url :
https://www.autohotkey.com/ the official site of AutoHotkey program.
https://artelogic.net/blog/top-7-web-resources-built-using-net/ It shows 7 site for web resuources built using net.
No.1 wkipedia https://en.wikipedia.org/wiki/
User avatar
boiler
Posts: 17404
Joined: 21 Dec 2014, 02:44

Re: How to open multiple urls.

29 Jan 2024, 21:51

OK, so now you have a reason for the RegExMatch. You still don’t have a MsgBox giving you the number of URLs. Is that what you’re thinking the variable url will contain? Again, look at the documentation page for RegExMatch. And I don’t think that your RegEx pattern is matching what you think it’s matching, at least not for the third item in your example.
User avatar
andymbody
Posts: 996
Joined: 02 Jul 2017, 23:47

Re: How to open multiple urls.

29 Jan 2024, 23:00

I agree with Boiler that you will want to review the Regex docs. But this is what you are looking for (url is now an array at the end of the regex). Your url was giving you the position of the match within the string. You also need a space at the end of the chrome command. And I also agree that a slightly different needle would be better.

try this...

Code: Select all

Loop parse, A_Clipboard, "`n", "`r"
	if (RegExMatch(A_LoopField, "i)https?://\S+", &url))
		Run "chrome.exe " url[] ; or url[0]
OR

Code: Select all

p := 0
while (p := RegExMatch(A_Clipboard, "i)https?://\S+", &url, ((p>0)?p+url.Len:1)))
	Run "chrome.exe " url[]
hancre
Posts: 251
Joined: 02 Jul 2021, 20:51

Re: How to open multiple urls.

30 Jan 2024, 01:23

@boiler
@andymbody

Thank you for your help. Your code work well.

But some url in my works show without 'https://' or 'http://".
so I want to extract urls with the end of domain.

I don't understand why the message box shows should show the number of urls.

I've read the document of regex. but I can't find the fault in my regular expression. @.@
User avatar
boiler
Posts: 17404
Joined: 21 Dec 2014, 02:44

Re: How to open multiple urls.

30 Jan 2024, 05:03

hancre wrote: I don't understand why the message box shows should show the number of urls.

I've read the document of regex. but I can't find the fault in my regular expression. @.@
Once again, the return value of RegExMatch is not the number of matches. It is the position of the match within the string. It’s in the RegExMatch documentation page under Return Value.

And also once again, if it did return a count of matches, why would you think it would tell you how many URLs are in your list? You are iterating a loop where you act on each line one at a time. There is only one URL in the string that it’s checking each time through the loop.
User avatar
andymbody
Posts: 996
Joined: 02 Jul 2017, 23:47

Re: How to open multiple urls.

30 Jan 2024, 06:41

hancre wrote:
30 Jan 2024, 01:23
But some url in my works show without 'https://' or 'http://".
Ok... so some something like this will be included in the list google.com
so I want to extract urls with the end of domain
So you are saying that you don't want the rest of the url after the domain?


If you want to count the urls, there is a different technique that can be used for this.
Try this to count all the urls (that include the desired TLDs) in the string

Code: Select all

RegExReplace(cb, "i)\S+\.(?:biz|co[m.]|edu|kr|net|org?)",, &count)
msgbox count
Can you tell me what you had in mind for this one? co\..+.
I don't think it will ever find this because co\. would be found first. Unless co\..+ comes first in the list. But if you place co\..+ first, it could cause issues during extraction by including unwanted trailing characters.

Also, will co always have a trailing dot? Or are you just trying to avoid those characters found in a word? In the second case, you can use a different technique (rather than the forced dot).
hancre
Posts: 251
Joined: 02 Jul 2021, 20:51

Re: How to open multiple urls.

30 Jan 2024, 20:07

I don't want to get 'count of urls' and domain identifier(.com, .or, .co.kr) and just extract urls.
I'd like to open multiple urls in the list together by AutoHotkey. ( showing the web pages for the multiple urls)

ex. test url :
https://www.autohotkey.com/ the official site of AutoHotkey program.
https://artelogic.net/blog/top-7-web-resources-built-using-net/ It shows 7 site for web resuources built using net.
No.1 wkipedia https://en.wikipedia.org/wiki/
http://sangrok.or.kr/topbuilder/ one of church in Kwangju
IBK bank → https://www.ibk.co.kr/


.co. is in front of the country abbreviation code.
.co.kr means korean domain.
.co.jp means japanese domain.

I've found
- .co would work without the country abbreviation code ( rary case ^^ )
- .or work with the country abbreviation code.

so to conclude, the script should open urls .co, .com, .or, .org


[Mod edit: Removed the quote tag that made your whole post look like it was a quote by andymbody.]
User avatar
andymbody
Posts: 996
Joined: 02 Jul 2017, 23:47

Re: How to open multiple urls.  Topic is solved

31 Jan 2024, 06:09

This should support all examples shown so far (including any two-character country). It also includes the trailing portion of the urls (if that is desired).

Code: Select all

#z:: {
	A_Clipboard := "", Sleep(100), Send("^c"), Sleep(100)
	TLD		:= "\.(?:biz|com|edu|net|org|(?:co|or)\.[a-z]{2})"	; add other top level domains to this list
	needle	:= "i)\S+?" TLD "\S*"								; includes trailing portion of url
	Loop parse, A_Clipboard, "`n", "`r"
		if (RegExMatch(A_LoopField, needle, &url))
			Run "chrome.exe " url[]
}
hancre
Posts: 251
Joined: 02 Jul 2021, 20:51

Re: How to open multiple urls.

01 Feb 2024, 00:30

@andymbody

Thanks a lot. IT works. ^^;;
I added "(?i) to open urls for uppercase such as FACEBOOK.COM.

Code: Select all

	TLD := "(?i)\.(?:biz|com|edu|net|org|(?:co|or)\.[a-z]{2})" ; add other top-level domains to this list
User avatar
andymbody
Posts: 996
Joined: 02 Jul 2017, 23:47

Re: How to open multiple urls.

01 Feb 2024, 00:45

hancre wrote:
01 Feb 2024, 00:30
I added "(?i) to open urls for uppercase such as FACEBOOK.COM.
In that case, you can remove the i) from i)\S+? (if you haven't already) since it serves the same purpose for the entire needle (AHK's version). Also... I separated the list from the main needle just to make edits a little easier.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Lpanatt and 58 guests