Jump to content

Read a variable off of a web page


 Share

Recommended Posts

Ok, I am looking to do something that sounds simple but is kicking my ass. I need to search a web page for a given string. Following that sting is some numbers. The numbers change but the sting does not. I would like to read those numbers into a variable. Here is an example of what I am looking for:

Word (12)

The 'word' is always the same. The brackets are always the same. It's the numbers that change. The numbers could be one, two or three digits long.

I am using this function to read in the HTML:

$body = _IEBodyReadHTML($o_IE)

I have read the help file on StringRegExp and do not fully understand it. I can search the HTML for 'Word (' and find that with no problems.

Any help in this would be greatly appreciated.

A little reading goes a long way. Post count means nothing.

Link to comment
Share on other sites

maybe

#include <IE.au3>

$oIE = _IECreate ()
_IENavigate ($oIE, "YOUR WEB ADDRESS")

$Find = "Word(" 


$body = _IEBodyReadHTML ($oIE)
$sloc = @TempDir & "\stest.txt"
FileDelete($sloc)
FileWrite($sloc, $sbody)
$sfile = FileOpen($sloc, 0)
While 2
    $sline = FileReadLine($sfile)
    If @error Then
        MsgBox(262208, "Fail", "The string was NOT found   ")
        FileClose($sfile)
        Exit
    EndIf
    If StringInStr($sline, $Find) Then
        MsgBox(64, "Success", "The string " & $Find & " was found   ", 5)
        $Found = stringbetween($sline, $Find, ")")
        MsgBox(64, "Found", "The string is" & $Found & "    ", 5)
               Exitloop
    EndIf
WEnd


Func stringbetween($str, $start, $end)
    $pos = StringInStr($str, $start)
    If Not @error Then
        $str = StringTrimLeft($str, $pos + StringLen($start) - 1)
        $pos = StringInStr($str, $end)
        If Not @error Then
            $str = StringTrimRight($str, StringLen($str) - $pos + 1)
            Return $str
        EndIf
    EndIf
EndFunc ;==>stringbetween

***** not tested *******

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

*VERY* close to working. First off, let me thank you though :)

Ok, it opens the page, gives me a dialogue saying the string was found. Then it shows the variable I want (THANK YOU THANK YOU THANK YOU), then it pops up a dialogue box saying the string was NOT found. Odd...

A little reading goes a long way. Post count means nothing.

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...