Jump to content

Read Html file and search for a string


Go to solution Solved by somdcomputerguy,

Recommended Posts

Posted

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)
 

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

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

Posted
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

  • Solution
Posted (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 by somdcomputerguy

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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...