AvaCompute Posted July 4, 2014 Share Posted July 4, 2014 (edited) Easy solution to find string in html file. FindStringByTag.au3 #include-once ;————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————— ; ; Title ………………………… : Find string by tag. ; Author(s) ……………… : AvaCompute ; AutoIt Version … : 3.3.12.0 ; Func FindStringByTag( $String , $StartString , $EndString = '' , $CaseSense = 2 , $Occurrence = 1 ) Local $pStartString , $pEndString , $StartStringLength $StartStringLength = StringLen( $StartString ) $pStartString = StringInStr( $String , $StartString , $CaseSense , $Occurrence ) If ( $pStartString == 0 ) Then Return SetError( 1 , @error , '' ) EndIf If ( $EndString ) Then $pEndString = StringInStr( $String , $EndString , $CaseSense , 1 , $pStartString + $StartStringLength ) If ( $pEndString == 0 ) Then Return SetError( 2 , @error , '' ) EndIf Return StringMid( $String , $pStartString + $StartStringLength , $pEndString - ( $pStartString + $StartStringLength )) Else Return StringLeft( $String , $pStartString - 1 ) EndIf EndFunc ;————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————— Sample: #include 'FindStringByTag.au3' ;————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————— ; 1 Tag ; $String = 'SSD 240 GB_A8ER37' $StartString = '_' $ProductName = FindStringByTag( $String , $StartString ) ConsoleWrite( '! [FindStringByTag] Product Name = ' & $ProductName & @CRLF ) ;————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————— ; 2 Tag ; $String = '<meta property="fb:app_id" content="176044105761845" />' $StartString = 'content="' $EndString = '"' $ContentName = FindStringByTag( $String , $StartString , $EndString ) ConsoleWrite( '! [FindStringByTag] Content Name = ' & $ContentName & @CRLF ) ;————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————— Result: ! [FindStringByTag] Product Name = SSD 240 GB ! [FindStringByTag] Content Name = 176044105761845 Edited July 4, 2014 by AvaCompute 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