Jump to content

Recommended Posts

Posted

Friends hi, how do I work with two regex?

My example code

$aWebAdress = "https://autoitscripttr.blogspot.com/atom.xml"

$aGetNewConnect = Connections($aWebAdress)

$aUrlregex1 = StringRegExp($aGetNewConnect, "(?i)href='([^']+)",3)
$aUrlregex2 = StringRegExp($aGetNewConnect, "(?i)href="([^&]+)",3)

$UBoun = UBound($aUrlregex1) Or UBound($aUrlregex2)

If isArray($aUrlregex1) Or isArray($aUrlregex1) then
    For $c in $UBoun
        ConsoleWrite($UBoun[$c] & @CRLF)
        ConsoleWrite("Count Url : " & $c & @CRLF)
    Next
EndIf

Func Connections($address)
    Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
    $oHTTP.Open("GET", $address, False)
    $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0")
    $oHTTP.SetRequestHeader("Accept-Language", "tr-TR,tr;q=0.8,en-US;q=0.5,en;q=0.3")
    $oHTTP.Send()
    If @error Then
        ConsoleWrite("Line : " & @ScriptLineNumber & " Connect Error " & @CRLF)
        $oHTTP = 0
        Return SetError(1)
    EndIf

    If $oHTTP.Status = 200 Then
        Local $sReceived = $oHTTP.ResponseText
        $oHTTP = Null
        Return $sReceived
    EndIf
   $oHTTP = Null
    Return -1
EndFunc

 

Posted (edited)

If you are trying to handle this atom.xml

you can use my Chilkat.au3 UDF:

and this free ActiveX component:
https://www.chilkatsoft.com/refdoc/xChilkatAtomRef.html

 

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

youtuber,

FYI,  this :

$UBoun = UBound($aUrlregex1) Or UBound($aUrlregex2)

returns "true" , and this :

For $c in $UBoun

is to be used with objects/arrays

The regex are good. Assuming that what you want to achieve is something like this, here is the correct working way  :

$aWebAdress = "https://autoitscripttr.blogspot.com/atom.xml"

$aGetNewConnect = Connections($aWebAdress)

$aUrlregex1 = StringRegExp($aGetNewConnect, "(?i)href='([^']+)",3)
If isArray($aUrlregex1)  then
    For $c = 0 to UBound($aUrlregex1)-1
        ConsoleWrite($c & @CRLF)
        ConsoleWrite("Count Url : " & $aUrlregex1[$c] & @CRLF)
    Next
EndIf

$aUrlregex2 = StringRegExp($aGetNewConnect, "(?i)href="([^&]+)",3)
If isArray($aUrlregex2)  then
    For $c = 0 to UBound($aUrlregex2)-1
        ConsoleWrite($c & @CRLF)
        ConsoleWrite("Count Url : " & $aUrlregex2[$c] & @CRLF)
    Next
EndIf


Func Connections($address)
    Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
    $oHTTP.Open("GET", $address, False)
    $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0")
    $oHTTP.SetRequestHeader("Accept-Language", "tr-TR,tr;q=0.8,en-US;q=0.5,en;q=0.3")
    $oHTTP.Send()
    If @error Then
        ConsoleWrite("Line : " & @ScriptLineNumber & " Connect Error " & @CRLF)
        $oHTTP = 0
        Return SetError(1)
    EndIf

    If $oHTTP.Status = 200 Then
        Local $sReceived = $oHTTP.ResponseText
        $oHTTP = Null
        Return $sReceived
    EndIf
   $oHTTP = Null
    Return -1
EndFunc

 

Posted

youtuber,

Or do you mean this (combining two regexps)...

$aWebAdress = "https://autoitscripttr.blogspot.com/atom.xml"

$aGetNewConnect = Connections($aWebAdress)

$aUrlregex1 = StringRegExp($aGetNewConnect, "(?i)href=(?:'|(?:"))([^'&]+)",3)
;$aUrlregex1 = StringRegExp($aGetNewConnect, "(?i)href='([^']+)",3)
If isArray($aUrlregex1)  then
    For $c = 0 to UBound($aUrlregex1)-1
        ConsoleWrite($c & @CRLF)
        ConsoleWrite("Count Url : " & $aUrlregex1[$c] & @CRLF)
    Next
EndIf

;~ $aUrlregex2 = StringRegExp($aGetNewConnect, "(?i)href="([^&]+)",3)
;~ If isArray($aUrlregex2)  then
;~     For $c = 0 to UBound($aUrlregex2)-1
;~         ConsoleWrite($c & @CRLF)
;~         ConsoleWrite("Count Url : " & $aUrlregex2[$c] & @CRLF)
;~     Next
;~ EndIf


Func Connections($address)
    Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
    $oHTTP.Open("GET", $address, False)
    $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0")
    $oHTTP.SetRequestHeader("Accept-Language", "tr-TR,tr;q=0.8,en-US;q=0.5,en;q=0.3")
    $oHTTP.Send()
    If @error Then
        ConsoleWrite("Line : " & @ScriptLineNumber & " Connect Error " & @CRLF)
        $oHTTP = 0
        Return SetError(1)
    EndIf

    If $oHTTP.Status = 200 Then
        Local $sReceived = $oHTTP.ResponseText
        $oHTTP = Null
        Return $sReceived
    EndIf
   $oHTTP = Null
    Return -1
EndFunc

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Posted (edited)

@mikell @kylomas Friends thank you for your answers.
How do I have an regex application where I just want to get pictures?

$aUrlregex2 = StringRegExp($aGetNewConnect, "(?i)href=(?:'|(?:"))([^'&]+jpg|gif|png|bmp)", 3)

or

$aUrlregex2 = StringRegExp($aGetNewConnect, "(?i)href=(?:'|(?:"))([^'&]+)([^.]+jpg|gif|png|bmp)", 3)

 

Edited by youtuber

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...