Jump to content

Assign text on webpage to a variable?


mdwerne
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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
Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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}

Link to comment
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
 Share

  • Recently Browsing   0 members

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