Jump to content
Sign in to follow this  
nirmalsalem

Read Html file and search for a string

Recommended Posts

nirmalsalem

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)
 

Share this post


Link to post
Share on other sites
Palestinian

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 by Palestinian

Share this post


Link to post
Share on other sites
somdcomputerguy

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.

Share this post


Link to post
Share on other sites
mikell

$text = FileRead("D:\AutoIT\AR123.html")

Share this post


Link to post
Share on other sites
nirmalsalem

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

Share this post


Link to post
Share on other sites
nirmalsalem
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

Share this post


Link to post
Share on other sites
somdcomputerguy

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 by somdcomputerguy
  • Like 2

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites
nirmalsalem

Hi somdcomputerguy

Your code worked superb!!!!! thank you :)

Share this post


Link to post
Share on other sites
nirmalsalem

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 :)

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  

×