HighlanderSword Posted September 30, 2011 Share Posted September 30, 2011 Hello, I'm looking to do a search in Autoit, something similar to the code below from Perl. I'm not having any luck getting this to work, the issue is with the before and after text that it needs to search for. I tried using StringRegexp and have had no luck with that. Any Ideas would be appreciated. Thanks Paul sub parseAttrHtml { my $file = shift; my $attrHtml; open (IN,$file) or die ("[PARSEATTRHTML] Can't open '$file' for input.\nError: $!\n"); { local( $/ ); # slurp mode $attrHtml = <IN>; close IN; } my $matchBefore = ' <!---------- \ ----------> <TABLE CLASS=MAINBODY WIDTH=100% CELLSPACING=0 CELLPADDING=1> <TR> <TD WIDTH=60></TD> <TD> <TABLE CLASS=MAINBODY WIDTH=100% CELLSPACING=0 CELLPADDING=1> '; my $matchAfter = ' </TABLE>'; my ($tableRows) = $attrHtml =~ m/$matchBefore(.*?)$matchAfter/s; parseAttrLinks(split(/\n/,$tableRows)); } Link to comment Share on other sites More sharing options...
hannes08 Posted September 30, 2011 Share Posted September 30, 2011 Hello HighlanderSword, it appears to me that you try to extract strings from a given string between two strings. So you might want to look for _StringBetween() in the helpfile. Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
JohnOne Posted September 30, 2011 Share Posted September 30, 2011 Your first step is to show the code you are "not having any luck" with. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
hannes08 Posted September 30, 2011 Share Posted September 30, 2011 Your first step is to show the code you are "not having any luck" with.Not a bad idea, either. Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
HighlanderSword Posted September 30, 2011 Author Share Posted September 30, 2011 Hello, First issue I run into is using the code below the $matchBefore = section of the code in perl this work with no issues I have tried taking each line and adding a quote at the end of the line and adding th strings together, that works but then when I perform a StringInstr or _Stringbetween the search does not find it and it does exist in the file it reads in. include <String.au3> $file=FileOpen('C:\mstrdd\eSMART (20110529135434)\Attribute.html') $data=FileRead($file) $matchBefore = ' <!---------- \ ----------> <TABLE CLASS=MAINBODY WIDTH=100% CELLSPACING=0 CELLPADDING=1> <TR> <TD WIDTH=60></TD> <TD> <TABLE CLASS=MAINBODY WIDTH=100% CELLSPACING=0 CELLPADDING=1> Link to comment Share on other sites More sharing options...
JohnOne Posted September 30, 2011 Share Posted September 30, 2011 That code is opening and reading a file, it is not trying to parse it in any fashion at all. How have you tried stringbetween or stringregexp?, please show AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
hannes08 Posted September 30, 2011 Share Posted September 30, 2011 Autoit does not support multiple line assignments as you try here. Instead you need to glue the lines together with a 'newline' in between: $lines = "line1" & @CRLF & "line2" & @CRLF & "line3" P.S. you can use the [ autoit] and [ /autoit] tags around your code to make it show correctly. Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
HighlanderSword Posted September 30, 2011 Author Share Posted September 30, 2011 Hello, I have tried the code below and no match is found on the string. What am i missing ? #include <String.au3> $file=FileOpen('C:\mstrdd\eSMART (20110529135434)\Attribute.html') $data=FileRead($file) $matchBefore = " <!---------- \ ---------->" & @crlf $matchBefore = $matchBefore & "<TABLE CLASS=MAINBODY WIDTH=100% CELLSPACING=0 CELLPADDING=1>" & @crlf $matchBefore = $matchBefore & " <TR>" & @crlf $matchBefore = $matchBefore & " <TD WIDTH=60></TD>" & @crlf $matchBefore = $matchBefore & " <TD>" & @crlf $matchBefore = $matchBefore & " <TABLE CLASS=MAINBODY WIDTH=100% CELLSPACING=0 CELLPADDING=1>" & @crlf MsgBox(0,"$matchBefore",$matchBefore) $matchafter= ' </TABLE>' $test=StringInStr($data,$matchBefore) MsgBox(0,"Results",$test) Link to comment Share on other sites More sharing options...
JohnOne Posted September 30, 2011 Share Posted September 30, 2011 Try Replacing @crlf with @cr or @lf AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
JohnOne Posted September 30, 2011 Share Posted September 30, 2011 It might even be that there are unseen whites paces in the before string. Perhaps you could put the exact string into a file and have it read in as a variable, much as you do the whole document. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
HighlanderSword Posted September 30, 2011 Author Share Posted September 30, 2011 Hello, I tried that as well and no match. I also attached the HTML file im reading in. Thanks PaulAttribute.html Link to comment Share on other sites More sharing options...
BrewManNH Posted September 30, 2011 Share Posted September 30, 2011 (edited) This <!---------- ----------> does not equal this <!---------- \ ---------->, which is why it's not finding a match. Edited September 30, 2011 by BrewManNH If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
hannes08 Posted September 30, 2011 Share Posted September 30, 2011 This <!---------- ----------> does not equal this <!---------- \ ---------->, which is why it's not finding a match. Sometimes solutions for problems we try to solve for hours can be that easy. Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
HighlanderSword Posted September 30, 2011 Author Share Posted September 30, 2011 Thanks I totaly missed that .... 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