Die Funktion IsUrl() streikt bei einem Doppelpunkt Topic is solved

Stelle Fragen zur Programmierung mit Autohotkey

Moderator: jNizM

User avatar
haichen
Posts: 631
Joined: 09 Feb 2014, 08:24

Re: Die Funktion IsUrl() streikt bei einem Doppelpunkt

05 Dec 2019, 11:23

Ich habe neben dem zuvor reparierten noch einen zweiten Regex, der mit einem CALLOUT arbeitet.

Code: Select all

IsURL2(sURL) {
   Return RegExMatch(sURL, "iO)^(?<Protocol>https?|ftp)://(?<Domain>(?:[\w-]+\.)+\w\w+)(?::(?<Port>\d+)(?CCallout))?/?(?!.*:.*/)(?<Path1>(?:[^:/?# ]*/?))/?(?<Path2>(?:[^/?# ]*/?)+)(?:\?(?<Query>[^#]+)?)?(?:\#(?<Hash>.+)?)?$") 
}

Callout(m) {
  if ((m.port<=65535) and (m.port>0))
    return 0
  return -1 ;the complete regexp fails
}
Johnny R
Posts: 348
Joined: 03 Oct 2013, 02:07

Re: Die Funktion IsUrl() streikt bei einem Doppelpunkt

05 Dec 2019, 12:19

Danke an alle! Für den Augenblick funktioniert diese Fassung jetzt scheinbar, vorläufig bis auf Weiteres!
Johnny R
Posts: 348
Joined: 03 Oct 2013, 02:07

Re: Die Funktion IsUrl() streikt bei einem Doppelpunkt

08 Dec 2019, 13:24

haichens letzte Version vom 5.12.2019 funktioniert jetzt bei mir seit einigen Tagen fehlerfrei. Danke nochmals!
Johnny R
Posts: 348
Joined: 03 Oct 2013, 02:07

Re: Die Funktion IsUrl() streikt bei einem Doppelpunkt

24 Aug 2021, 07:30

Hallo, ich hatte schon wieder mit einer Wikipedia-Url zu tun, die von der Funktion nicht als Url erkannt wird, nämlich
MsgBox % IsUrl("https://en.wikipedia.org/wiki/User:%CE%9F%CE%A5%CE%A4%CE%99%CE%A3")
Kann man da etwas machen oder ist dieser String zu exotisch? Grüße!
garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: Die Funktion IsUrl() streikt bei einem Doppelpunkt

24 Aug 2021, 14:54

function von user @haichen und @teadrinker

Code: Select all

;- URL encode-decode    user 'teadrinker'
;- https://www.autohotkey.com/boards/viewtopic.php?f=76&t=84825&p=372265#p372265

;url2:="https%3A%2F%2Fwww.google.com%2Fsearch%3Fq%3D%E6%9D%8E%E9%A6%99%E8%98%AD"
;url2:="https%3A%2F%2F%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82_%D0%A1%D0%BF%D0%B0%D1%81%D0%B8%D0%B1%D0%BE_%D0%B1%D0%BE%D0%BB%D1%8C%D1%88%D0%BE%D0%B5_stackoverflow.com%2F"
url2:="https://en.wikipedia.org/wiki/User:%CE%9F%CE%A5%CE%A4%CE%99%CE%A3"
decoded := EncodeDecodeURI(url2, false)
encoded := EncodeDecodeURI(decoded)
isurl:=IsUrl2(decoded)
msgbox,ORIG=`n%url2%`n-------------------------------------------------`nDECODED=`n%decoded%`n-------------------------------------------------`nENCODED=`n%encoded%`n-------------------------------------------------`nISURL=%isurl%
return
;---------------
;- from user 'teadrinker'
EncodeDecodeURI(str, encode := true, component := true) {
   static Doc, JS
   if !Doc {
      Doc := ComObjCreate("htmlfile")
      Doc.write("<meta http-equiv=""X-UA-Compatible"" content=""IE=9"">")
      JS := Doc.parentWindow
      ( Doc.documentMode < 9 && JS.execScript() )
   }
   Return JS[ (encode ? "en" : "de") . "codeURI" . (component ? "Component" : "") ](str)
}
;=============================================================================
;- https://www.autohotkey.com/boards/viewtopic.php?f=9&t=70336&start=20     user 'haichen'
IsURL2(sURL) {
   Return RegExMatch(sURL, "iO)^(?<Protocol>https?|ftp)://(?<Domain>(?:[\w-]+\.)+\w\w+)(?::(?<Port>\d+)(?CCallout))?/?(?!.*:.*/)(?<Path1>(?:[^:/?# ]*/?))/?(?<Path2>(?:[^/?# ]*/?)+)(?:\?(?<Query>[^#]+)?)?(?:\#(?<Hash>.+)?)?$") 
}

Callout(m) {
  if ((m.port<=65535) and (m.port>0))
    return 0
  return -1 ;the complete regexp fails
}
;=============================================================================
Johnny R
Posts: 348
Joined: 03 Oct 2013, 02:07

Re: Die Funktion IsUrl() streikt bei einem Doppelpunkt

25 Aug 2021, 03:52

Hallo garry, vielen Dank für Deine Mühe. Beim Testen ergab sich aber, dass die Funktion mit einer anderen WP-Url immer noch nicht funktioniert, nämlich
MsgBox % IsUrlString("https://en.wikipedia.org/wiki/Special:Contributions/%CE%9F%CE%A5%CE%A4%CE%99%CE%A3")
Das Ding ist offenbar ein Buch mit sieben Siegeln...
just me
Posts: 9464
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Die Funktion IsUrl() streikt bei einem Doppelpunkt

25 Aug 2021, 04:53

Johnny R wrote: Hallo, ich hatte schon wieder mit einer Wikipedia-Url zu tun, die von der Funktion nicht als Url erkannt wird, nämlich
MsgBox % IsUrl("https://en.wikipedia.org/wiki/User:%CE%9F%CE%A5%CE%A4%CE%99%CE%A3")
Kann man da etwas machen oder ist dieser String zu exotisch? Grüße!
Moin,

diese URL funktioniert hier mit:

Code: Select all

MsgBox % IsUrl2("https://en.wikipedia.org/wiki/User:%CE%9F%CE%A5%CE%A4%CE%99%CE%A3")
MsgBox % IsUrl2("https://en.wikipedia.org/wiki/Special:Contributions/%CE%9F%CE%A5%CE%A4%CE%99%CE%A3")


IsURL2(sURL) {
   Return RegExMatch(sURL, "iO)^(?<Protocol>https?|ftp)://(?<Domain>(?:[\w-]+\.)+\w\w+)(?::(?<Port>\d+)(?CCallout))?/?(?!.*:.*/)(?<Path1>(?:[^:/?# ]*/?))/?(?<Path2>(?:[^/?# ]*/?)+)(?:\?(?<Query>[^#]+)?)?(?:\#(?<Hash>.+)?)?$")
}

Callout(m) {
  if ((m.port<=65535) and (m.port>0))
    return 0
  return -1 ;the complete regexp fails
}
Bei der zweiten URL scheitert es am letzten Slash /. Wenn die URL gültig ist, müsste die Prüfung im RegEx noch mal geändert werden.
Johnny R
Posts: 348
Joined: 03 Oct 2013, 02:07

Re: Die Funktion IsUrl() streikt bei einem Doppelpunkt

25 Aug 2021, 05:08

Hallo just me, die zweite Url scheint schon gültig zu sein, weil sie direkt aus WP kopiert ist und im Übrigen beim Draufklicken auch ordnungsgemäß fuinktioniert. Grüße!
garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: Die Funktion IsUrl() streikt bei einem Doppelpunkt

25 Aug 2021, 07:25

hier noch 2 Beispiele
in diesem script beide benutzt für Test

Code: Select all

;-------- saved at Montag, 7. Juli 2014 08:15:52 --------------
;-------- https://autohotkey.com/board/topic/112151-checking-network-status/
;- CHECK internet connection & URL ------------------------------------------------

;urlx:="https://en.wikipedia.org/wiki/User:%CE%9F%CE%A5%CE%A4%CE%99%CE%A3"                    ;- correct
urlx:="https://en.wikipedia.org/wiki/Special:Contributions/%CE%9F%CE%A5%CE%A4%CE%99%CE%A3"  ;- correct
;urlx:="https://en.wikipedia.org/wiki/Special:Contributions/%CE%9F%CE%A5%CE%A4%CE%99%CE%A1"  ;- nicht correct aber umgeleitet
;urlx:="https://en.wikipediax.org/wiki/Special:Contributions/%CE%9F%CE%A5%CE%A4%CE%99%CE%A1"  ;- URL falsch not exist
;----
;urlx:="https://www.radio.de/s/hpr1classiccountry"
;urlx:="http://87.98.130.255:8188/stream"          ;- HPR1 classic country
;urlx:="http://87.98.130.255:8188/played.html"
goto,example1

example1:
FLAG_ICC_FORCE_CONNECTION=1
if !DllCall("Wininet.dll\InternetGetConnectedState", "UInt*", flag, "UInt", 0)
       {
	aa1:= % "InternetGetConnectedState() failed " flag " " A_LastError
        msgbox, 262208,NO SUCCES,AA1=%aa1%
	return
        }
flagstr =
if (flag & 0x01)
	flagstr .= "INTERNET_CONNECTION_MODEM`n"
if (flag & 0x02)
	flagstr .= "INTERNET_CONNECTION_LAN`n"
if (flag & 0x04)
	flagstr .= "INTERNET_CONNECTION_PROXY`n"
if (flag & 0x10)
	flagstr .= "INTERNET_RAS_INSTALLED`n"
if (flag & 0x20)
	flagstr .= "INTERNET_CONNECTION_OFFLINE`n"
if (flag & 0x40)
	flagstr .= "INTERNET_CONNECTION_CONFUGURED`n"
aa3:= % flagstr "InternetGetConnectedState() succeed " flag
if !DllCall("Wininet.dll\InternetCheckConnection", "Str",urlx,"UInt", FLAG_ICC_FORCE_CONNECTION, "UInt", 0)
        {
	aa2:= % "InternetCheckConnection() failed " A_LastError
        msgbox, 262208,NO SUCCES,AA2=%aa2%
	return
        }
;msgbox,aa3=%aa3%
;return


example2:
;--- example for try/catch/error CHECK URL ------------------
xx:=ComObjCreate("WinHttp.WinHttpRequest.5.1")   ;-Create the Object
;-- catch get error but don't show failure
;ComObjError(false)
;xx.Silent := True    ;- script failure = off
xx.SetTimeouts(500,500,500,500)
try {
    xx.Open("GET",urlx)                           ;-Open communication
    xx.Send()                                   ;-Send the "get" request
    aac=
    aac:=xx.ResponseText                        ;-Set the "aac" variable to the response
    ;msgbox, 262208,%urlx% exists,%aa4%`n`n%urlx%`n-----------------`n %aac%
} catch e {
    xxx:=e.Message
    msgbox, 262208,NO SUCCESS ERROR ,AA3=%aa3%`n------------`nError=Catch`n%urlx%`n NOT exists`n------------------------------------------`n%xxx%`n------------------------------------------,
    return
    }
msgbox, 262208,SUCCESS,AA3=%aa3%`n------------`nURL EXISTS=`n%urlx%
return
;==================================================================
Johnny R
Posts: 348
Joined: 03 Oct 2013, 02:07

Re: Die Funktion IsUrl() streikt bei einem Doppelpunkt

25 Aug 2021, 09:25

Hallo garry und vielen Dank, aber ich fürchte, das ist jetzt alles zu hoch für mich, jedenfalls ohne Erläuterungen. Mir liegt nur daran, dass IsUrl() diese exotischen WP-Urls als Urls erkennt. Grüße!
garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: Die Funktion IsUrl() streikt bei einem Doppelpunkt

26 Aug 2021, 04:45

man kann aus dem Script eine Funktion erstellen
hier nur ein Beispiel mit gosub ( added Funktion 'internetconnected' )

Code: Select all

#warn
;urlx:="https://en.wikipedia.org/wiki/Special:Contributions/%CE%9F%CE%A5%CE%A4%CE%99%CE%A3"  ;- correct
;urlx:="https://en.wikipedia.org/wiki/Special:Contributions/%CE%9F%CE%A5%CE%A4%CE%99%CE%A1"  ;- nicht correct aber umgeleitet d.h URL exist
urlx:="https://en.wikipediax.org/wiki/Special:Contributions/%CE%9F%CE%A5%CE%A4%CE%99%CE%A1"  ;- URL falsch not exist
;- case-1 INTERNETCONNECTED  ( modem / wlan )
aaa:= InternetConnected()
if aaa=0
  {
  msgbox, 262208,InternetCheck,Internet NOT connected
  exitapp
  }
msgbox, 262208,InternetCheck ,Internet OK
;----------------------------------------------
;- continue here to check if URL exist
;----------------------------------------------
xx:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
gosub,a1
;------------
if (result=1)
   {
   msgbox, 262208,SUCCESS,URL=%urlx%=`nURL exists
   ;- continue here if OK
   }
if (result=0)
   {
   msgbox, 262208,NO SUCCESS,URL=%urlx%=`nURL NOT exists
   exitapp
   }
return
;--------- gosub check URL -------------------
a1:
try {
    xx.Open("GET",urlx)
    xx.Send()
    result=1
} catch e {
    result=0
    }
return
;==================================================================
internetConnected(){ ;https://autohotkey.com/boards/viewtopic.php?f=5&t=23127
    static url:="http://google.com"                         ;-user masonjar13
    if(!dllCall("Wininet.dll\InternetGetConnectedState","Str","","Int",0))
        return 0
    if(!dllCall("Wininet.dll\InternetCheckConnection","Str",url,"Uint",1,"Uint",0))
        return 0
    return 1
}
;==================================================================

Return to “Ich brauche Hilfe”

Who is online

Users browsing this forum: No registered users and 87 guests