Snarg Posted March 11, 2006 Share Posted March 11, 2006 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 More sharing options...
Valuater Posted March 11, 2006 Share Posted March 11, 2006 (edited) maybe expandcollapse popup#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 March 11, 2006 by Valuater Link to comment Share on other sites More sharing options...
Snarg Posted March 11, 2006 Author Share Posted March 11, 2006 *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 More sharing options...
Valuater Posted March 11, 2006 Share Posted March 11, 2006 (edited) Welcome i didnt put.. "EXITLOOP" after the Found Messagebox 8) Edited March 11, 2006 by Valuater Link to comment Share on other sites More sharing options...
Snarg Posted March 11, 2006 Author Share Posted March 11, 2006 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. Link to comment Share on other sites More sharing options...
Valuater Posted March 11, 2006 Share Posted March 11, 2006 heck.... I dont understand.... *why* it works... 8) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now