Sign in to follow this  
Followers 0
RNM

String Manipulation in Web Page

6 posts in this topic

Hi All,

I have a web page that I need to pull a date from. The string in the web page shows:

(Current server time:10/20/2010 07:59:13)

I need the date... how do I find and retrieve that value?

Thanks!

Share this post


Link to post
Share on other sites



Something like this:

$sString = BinaryToString(InetRead("your URL"))
;$sString = "The page shows:(Current server time:10/20/2010 07:59:13)I need the date..." ; Testdata
$iPos = StringInStr($sString, "(Current server time:")
$sDateTime = StringMid($sString, $iPos + 21, 19)
MsgBox(0, "", $sDateTime)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

If the format is completely consistent, StringTrimRight and ...Left would do it, too.

William

Share this post


Link to post
Share on other sites

$sString = BinaryToString(InetRead("your URL"))
$sCurrentTime = StringRegExpReplace($sString, "(?i).*current\s.+time:\s?([\d/]+)\s.+", "$1")


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

$sString = BinaryToString(InetRead("your URL"))
$sCurrentTime = StringRegExpReplace($sString, "(?i).*current\s.+time:\s?([\d/]+)\s.+", "$1")

Perfect... thanks everyone!

Share this post


Link to post
Share on other sites

If you want to work with the DOM, it might look something like this:

#include <IE.au3>

$sTimeURL = "http://www.time.gov/timezone.cgi?UTC/s/0"
$oIE = _IECreate($sTimeURL)
$colTD = _IETagNameGetCollection($oIE, "td")
For $oTD In $colTD
    If StringRegExp($oTD.innerText, "\d{2}\:\d{2}\:\d{2}", 0) Then
        $aTime = StringRegExp($oTD.innerText, "(?s)(?U)(\d{2}\:\d{2}\:\d{2}).+([[:alpha:]]+\,\s[[:alpha:]]+\s\d{2},\s\d{4})", 1)
        If IsArray($aTime) and UBound($aTime) >= 2 Then
            ConsoleWrite("Time = " & $aTime[0] & @CRLF & "Date = " & $aTime[1] & @LF)
        EndIf
        ExitLoop
    EndIf
Next

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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