Sign in to follow this  
Followers 0
Snarg

Read a variable off of a web page

6 posts in this topic

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.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Welcome

i didnt put.. "EXITLOOP" after the Found Messagebox

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

Works like a charm! Thank you kind sir. Now I just need to understand *why* it works...


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

Share this post


Link to post
Share on other sites

heck....

I dont understand.... *why* it works...

8)


NEWHeader1.png

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