Sign in to follow this  
Followers 0
youtuber

InetRead StringRegExp problem?

8 posts in this topic

#1 ·  Posted (edited)

I want to get the expiration date

Local $sStr = InetRead("http://who.is/whois/autoitscript.com",0)
If @error Then
   MsgBox(16,"Error!","Unable to retrieve information")
Else
   $sStr = BinaryToString($sStr, 0)
EndIf

Local $info

Local $expiration_date = StringRegExp($sStr, 'visibility: visible;">','</span></p>', 3)
If UBound($expiration_date) = 3 Then
   $info = "Received data: " & $expiration_date[0] & @CRLF
EndIf

MsgBox(64,"Test",$info)

 

Edited by youtuber

Share this post


Link to post
Share on other sites



https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm

StringRegExp.htm  Sample 1 :

$aArray = StringRegExp('<test>a</test> <test>b</test> <test>c</Test>', '(?i)<test>(.*?)</test>', $STR_REGEXPARRAYMATCH, $iOffset)

I use that on your script this give :

Local $expiration_date = StringRegExp($sStr, '(?i)visibility: visible;">(.*?)</span></p>', 3)

Result : 5 May 2017

1 person likes this

Share this post


Link to post
Share on other sites

How could this be?

CgF7X3C.png

Local $sStr = InetRead("https://www.autoitscript.com/forum/forum/2-autoit-general-help-and-support/",0)
If @error Then
   MsgBox(16,"Error!","Unable to retrieve information")
Else
   $sStr = BinaryToString($sStr, 0)
EndIf

Local $info

Local $expiration_date = StringRegExp($sStr, '(?i)<span itemprop="name headline">(.*?)</span>', 3)
If UBound($expiration_date) = 3 Then
   $info = "Received data: " & $expiration_date[0] & @CRLF
EndIf

MsgBox(64,"Test",$info)

 

Share this post


Link to post
Share on other sites

maybe considerer _StringBetween() :

#include <Array.au3>
#include <String.au3>
Local $expiration_date = _StringBetween($sStr, '<span itemprop="name headline">','</span>')
_ArrayDisplay($expiration_date)

 

1 person likes this

Share this post


Link to post
Share on other sites

@Synapsee Thank you for answer

Is this code right?

#include <Array.au3>
#include <String.au3>
Local $sStr = InetRead("https://www.autoitscript.com/forum/forum/2-autoit-general-help-and-support/",0)
If @error Then
   MsgBox(16,"Error!","Unable to retrieve information")
Else
   $sStr = BinaryToString($sStr, 0)
EndIf

 Local $expiration_date = _StringBetween($sStr, '<span itemprop="name headline">','</span>')

_ArrayDisplay($expiration_date)

 

Share this post


Link to post
Share on other sites

yeah it's correct, the array is feed...

minor improve : use _StringBetween error

#include <Array.au3>
#include <String.au3>
Local $sStr = InetRead("https://www.autoitscript.com/forum/forum/2-autoit-general-help-and-support/",0)
If @error Then
   MsgBox(16,"Error!","Unable to retrieve information")
Else
   $sStr = BinaryToString($sStr, 0)
EndIf

 Local $expiration_date = _StringBetween($sStr, '<span itemprop="name headline">','</span>')
If @error Then
    MsgBox(16,"Error!","_StringBetween : No strings found")
Else
    _ArrayDisplay($expiration_date)
EndIf

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

#include <Array.au3>
#include <String.au3>
Local $sStr = InetRead("http://youtubertr.com/StringRegExp.html",0)
If @error Then
   MsgBox(16,"Error!","Unable to retrieve information")
Else
   $sStr = BinaryToString($sStr, 0)
EndIf

Local $expiration_date = StringRegExp($sStr, '(?i)stop-rank">(.*?)</span></font>', 3)
If @error Then
    MsgBox(16,"Error!","StringRegExp error")
Else
    _ArrayDisplay($expiration_date)
    Msgbox(0, "Target", $expiration_date[0])
    ;$expiration_date[0]
    ;Array is $expiration_date
    ;[0] is for array line number
EndIf

Edit :

i warning you about $INET_LOCALCACHE / $INET_FORCERELOAD :

Quote

InetRead ( "URL" [, options = 0] )

options :

$INET_LOCALCACHE (0) = Get the file from local cache if available (default).

$INET_FORCERELOAD (1) = Forces a reload from the remote site.

 

Edited by Synapsee
1 person likes this

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0