nirmalsalem Posted March 19, 2014 Share Posted March 19, 2014 Hi, I am very new to Autoit and I am trying to read an html file and trying to find a string in that html file. Below is the part of my code. But it is returning msg as 0. Please suggest. $oIE = _IECreate () _IENavigate($oIE, "D:AutoITAR123.html") ;WinSetState("Test","",@SW_MAXIMIZE) ;$sSearchText = "SR_NUMBER:" Local $sText = _IEBodyReadHTML($oIE) MsgBox(0, "Body Text", $sText) _IEQuit($oIE) Link to comment Share on other sites More sharing options...
Palestinian Posted March 19, 2014 Share Posted March 19, 2014 (edited) Hi, I am very new to Autoit and I am trying to read an html file and trying to find a string in that html file. Below is the part of my code. But it is returning msg as 0. Please suggest. $oIE = _IECreate () _IENavigate($oIE, "D:AutoITAR123.html") ;WinSetState("Test","",@SW_MAXIMIZE) ;$sSearchText = "SR_NUMBER:" Local $sText = _IEBodyReadHTML($oIE) MsgBox(0, "Body Text", $sText) _IEQuit($oIE) Welcome to AutoIt. $oIE = _IECreate () _IENavigate($oIE, "D:\AutoIT\AR123.html") ;WinSetState("Test","",@SW_MAXIMIZE) Local $sText = _IEBodyReadHTML($oIE) $sNumber = StringInStr($sText, 'SR_NUMBER:') If $sNumber Then MsgBox(0, "Body Text", $sNumber) _IEQuit($oIE) EndIf Try that one. P.S: Please use the AutoIt tags around your code to make it easier to read for everyone else. Edited March 19, 2014 by Palestinian Link to comment Share on other sites More sharing options...
somdcomputerguy Posted March 19, 2014 Share Posted March 19, 2014 Do you have this line at the top of your script? - #include <IE.au3> And when you post code on the forum, you should use the code tags. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
mikell Posted March 19, 2014 Share Posted March 19, 2014 $text = FileRead("D:\AutoIT\AR123.html") Link to comment Share on other sites More sharing options...
nirmalsalem Posted March 20, 2014 Author Share Posted March 20, 2014 Hi Palestinian, Thanks for your immediate reply and solution. I executed your code, it is navigating and opening the html file in the browser, but it is not displaying any msg. Also I am trying to search for the same string as you have used in your code i.e., "SR_NUMBER". But I want to search this string and want to retierve the Number next to this string. AR123.html Link to comment Share on other sites More sharing options...
nirmalsalem Posted March 20, 2014 Author Share Posted March 20, 2014 Mikell, Thanks for your response. Tried using FileRead as you have suggested, I am trying to find a String "SR_NUMBER: " and want to retreived the Number next to this string. Attached the file for reference. AR123.html Link to comment Share on other sites More sharing options...
Solution somdcomputerguy Posted March 20, 2014 Solution Share Posted March 20, 2014 (edited) This is one way to do it. Certainly others will show you different ways to skin this cat. They all will do pretty much the same thing, just in different ways. It'll be up to you to decide which one fits with your whole script better. #include <String.au3> Local $file = FileOpen("AR123.html", 0), _ $data = FileRead($file), _ $found = _StringBetween($data, 'SR_NUMBER: ', '<br>') MsgBox(0, '', $found[0]) Edited March 20, 2014 by somdcomputerguy nirmalsalem and krista611 2 - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
mikell Posted March 20, 2014 Share Posted March 20, 2014 $text = FileRead("AR123.html") Msgbox(0,"", StringRegExpReplace($text, '(?s).+SR_NUMBER:\s*([^<]+).+', "$1") ) nirmalsalem 1 Link to comment Share on other sites More sharing options...
nirmalsalem Posted March 20, 2014 Author Share Posted March 20, 2014 Hi somdcomputerguy Your code worked superb!!!!! thank you Link to comment Share on other sites More sharing options...
nirmalsalem Posted March 20, 2014 Author Share Posted March 20, 2014 Hi Mikell, Tried your code and really it is awesome one with the single line. Your code made to learn the string functions more. thank you 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