Sign in to follow this  
Followers 0
mdwerne

Assign text on webpage to a variable?

7 posts in this topic

Hello,

Can someone please point me in the right direction? I'm working on a script where I need to create a variable based on text on a given web page.

This is the page: http://www.symantec.com/business/security_response/definitions.jsp

and I need to grab the "Sequence Number:" into a variable.

I don't need working code, just a push in the right direction so I can figure it out myself.

Thanks,

-Mike

P.S. I did a few searches and all that jumps out is _IEBodyReadText in IE.au3 - is that on the right track?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You can use INetRead to get the whole page into a variable then use StingInStr or something similar to search for the needed string.

Be aware to use BinaryToString to convert the result of InetRead to text.

Or you can use the _IE* functions to get the html source, the displayed text or an html object.

Edited by water

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

#3 ·  Posted (edited)

You can use INetRead to get the whole page into a variable then use StingInStr or something similar to search for the needed string.

Be aware to use BinaryToString to convert the result of InetRead to text.

Or you can use the _IE* functions to get the html source, the displayed text or an html object.

Thanks water, I'll take a look. Edited by mdwerne

Share this post


Link to post
Share on other sites

Something like this should work. I download the html code so I can determine when the number ends.

#include <ie.au3>
$oIE = _IECreate("http://www.symantec.com/business/security_response/definitions.jsp", 0, 0)
$sString = _IEBodyReadHTML($oIE)
$iPosSeqStart = StringInStr($sString, "Sequence Number: ")
$iPosSeqEnd = StringInStr($sString, "<br",0, 1, $iPosSeqStart)
ConsoleWrite(StringMid($sString, $iPosSeqStart+17, $iPosSeqEnd-$iPosSeqStart-17) & @CRLF)
_IEQuit($oIE)

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

Something like this should work. I download the html code so I can determine when the number ends.

#include <ie.au3>
$oIE = _IECreate("http://www.symantec.com/business/security_response/definitions.jsp", 0, 0)
$sString = _IEBodyReadHTML($oIE)
$iPosSeqStart = StringInStr($sString, "Sequence Number: ")
$iPosSeqEnd = StringInStr($sString, "<br",0, 1, $iPosSeqStart)
ConsoleWrite(StringMid($sString, $iPosSeqStart+17, $iPosSeqEnd-$iPosSeqStart-17) & @CRLF)
_IEQuit($oIE)

Well heck, look what ya gone an done...ya gave me the answer. Yes, it works perfectly. Thank you!

I'm sure my boss will be happy that you gave him back two hours of my time that I would have spent trying to work this out on my own.

Have a great weekend amigo!!

-Mike

Share this post


Link to post
Share on other sites

I hope your boss will be so happy that he gives you a raise ;)


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

#7 ·  Posted (edited)

Here's taking it to another level:

;Tell us what site we want to be checking
$site = "http://www.symantec.com/business/security_response/definitions.jsp"

;Get the source of the site (force reload) and
    ;convert it to human-readable form
;or
    ;show the error thrown
$read = InetRead($site, 1)
If Not @error Then
    $read = BinaryToString($read)
Else
    MsgBox(262144, "Error", "@error : " & @error)
EndIf

;Specify how many and which items to look up
$items = 6
Local $item[$items], $data
$item[0] = "Virus Definitions created"
$item[1] = "Virus Definitions released"
$item[2] = "Defs Version:"
$item[3] = "Sequence Number:"
$item[4] = "Extended Version:"
$item[5] = "Total Detections (Threats & Risks):"

;Add the items and their values to the $data variable
For $i = 0 To $items-1
    $data &= $item[$i] & @CRLF & find($read, $item[$i]) & @CRLF
Next

;get rid of trailing @CRLF
$data = StringTrimRight($data, 2)

;Show us the items and their values
MsgBox(262144, "", $data)

;Split the human-readable source by the item
;Split the second portion of the previously split data by a left carat
;Return the information we're supposed to be finding
Func find($a, $b)
    $split = StringSplit($a, $b, 1)
    $seq = StringSplit($split[2], "<")
    Return $seq[1]
EndFunc
Edited by cembry90

AutoIt Stuff:

 

UDFs: {Grow}

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