Flawblure Posted February 18, 2006 Share Posted February 18, 2006 (edited) Theres gotta be a simple way to do this. Logically, I just can't figure it out though. I have a script that parses through HTML, leaving only a few things. But what I need is for it to just keep a few lines and it's extremely difficult to parse everything but these lines away since there muddled in so much other stuff. What I'm parsing is long... so I attached it as a .txt file. I basically want to look at the source, and then take away everything except for whatever starts with java script:mpd( ends with ); and then put whatever was in between those two into a variable. It's a coordinate system in a game I play, so the end result would look something like: java script:mpd(-1, 2); And then it would have a list of differant ones of those, and then have each value, IE: (-1, 2) as a variable. But those values change as the game changes, so I can't just look for that specific value. I tried to use my HTML parsing script and work in reverse, but it didnt work :/.GK_test.txt Edited February 18, 2006 by Flawblure Link to comment Share on other sites More sharing options...
JoshDB Posted February 18, 2006 Share Posted February 18, 2006 Yeah, you may want to post some example code Ha, I haven't been on these forums since... 2006, almost. Behold, my legacy signature:My AutoIt idol is Valuater. You know you love him, too.My Stuff: D&D AGoT Tools Suite Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 18, 2006 Moderators Share Posted February 18, 2006 Theres gotta be a simple way to do this. Logically, I just can't figure it out though. I have a script that parses through HTML, leaving only a few things. But what I need is for it to just keep a few lines and it's extremely difficult to parse everything but these lines away since there muddled in so much other stuff.What I'm parsing is long... so I attached it as a .txt file. I basically want to look at the source, and then take away everything except for whatever starts withjava script:mpd( ends with ); and then put whatever was in between those two into a variable.It's a coordinate system in a game I play, so the end result would look something like: java script:mpd(-1, 2); And then it would have a list of differant ones of those, and then have each value, IE: (-1, 2) as a variable. But those values change as the game changes, so I can't just look for that specific value.I tried to use my HTML parsing script and work in reverse, but it didnt work :/.Um... No Script to work off of? Edit:Reminds me of the 'Noob comment I made in a post last night'! Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Flawblure Posted February 18, 2006 Author Share Posted February 18, 2006 Um... No Script to work off of? Edit: Reminds me of the 'Noob comment I made in a post last night'! All I have is the ParseHTML script, but that removes it.... but here it is.... expandcollapse popupGlobal $sWorkVar, $sWorkVar2, $iCodeFlag, $var, $i, $char $char = 0 $sFilePath = FileOpenDialog ( "Select HTML file to strip.", "My Computer", "HTML (*.html)|HTM (*.htm)" , 1 ) $begin = TimerInit() $sFileContent = FileRead($sFilePath) $sWorkVar = $sFileContent While 1 If StringLeft($sWorkVar, 15) = "java script:mpd(" Then $iCodeFlag = 1 EndIf If StringLeft($sWorkVar, 1) = ")" Then $iCodeFlag = 0 $sWorkVar = StringTrimLeft($sWorkVar, 1) EndIf While $iCodeFlag = 1 If StringLeft($sWorkVar, 1) = ")" Then ExitLoop $sWorkVar = StringTrimLeft($sWorkVar, 1) WEnd While $iCodeFlag = 0 If StringLeft($sWorkVar, 15) = "java script:mpd(" Then ExitLoop If Not StringInStr($sWorkVar, ")") Then ExitLoop $sWorkVar2 = $sWorkVar2 & StringLeft($sWorkVar, 1) $sWorkVar = StringTrimLeft($sWorkVar, 1) WEnd If Not StringInStr($sWorkVar, ")") Then $sWorkVar2 = $sWorkVar2 & $sWorkVar ExitLoop EndIf WEnd $var = IniReadSection(@ScriptDir & "\Strip HTML.ini", "BoilerPlate") If @error Then MsgBox(4096, "", "Error occured, probably no INI file.") Else For $i = 1 To $var[0][0] $sWorkVar2 = StringReplace($sWorkVar2,$var[$i][1],"") ;StringReplace ( "string", "searchstring", "replacestring") Next While StringInStr($sWorkVar2,@CRLF) Or StringInStr($sWorkVar2,@CR) Or StringInStr($sWorkVar2,@LF) $sWorkVar2 = StringReplace($sWorkVar2,@CRLF,"") $sWorkVar2 = StringReplace($sWorkVar2,@CR,"") $sWorkVar2 = StringReplace($sWorkVar2,@LF,"") WEnd EndIf FileWrite ( @ScriptDir & "\Stripped.TXT", @YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & $sWorkVar2 & @CRLF ) $dif = Round ( (TimerDiff($begin)/1000) , 4 ) MsgBox(0,"Time To Process The File",$dif & " seconds...", 5) MsgBox(0,"Result","The stripped data is " & $sWorkVar2, 5 ) Exit Written by gene... i just changed what it removed. But as I said, it removes it. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 18, 2006 Moderators Share Posted February 18, 2006 http://www.autoitscript.com/forum/index.php?showtopic=19718 Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Flawblure Posted February 18, 2006 Author Share Posted February 18, 2006 http://www.autoitscript.com/forum/index.php?showtopic=19718 Func _GetStringBetween($String, $Starting, $Ending) If StringInStr($String, $Starting) And StringInStr($String, $Ending) Then $StL = StringTrimLeft($String, StringInStr($String, $Starting) - 1) $SeL = StringLeft($StL, StringInStr($StL, $Ending) + 1) $StringBetween = StringTrimLeft(StringTrimRight($SeL, StringLen($Ending)), StringLen($Starting)) Return $StringBetween Else Return 0 EndIf EndFunc It works awesomely! But using it returns one value. I know I have to use a loop in order for it to return all of the values, but how would I determine when to end the loop, and to move onto the next one...? Link to comment Share on other sites More sharing options...
Valuater Posted February 18, 2006 Share Posted February 18, 2006 Um... No Script to work off of? Edit:Reminds me of the 'Noob comment I made in a post last night'!Was that me???... lol8) Link to comment Share on other sites More sharing options...
Flawblure Posted February 18, 2006 Author Share Posted February 18, 2006 (edited) K, I got a loop for it going now, but it only takes 2 values. Global $StringBetween Func _GetStringBetween($String, $Starting, $Ending) If StringInStr($String, $Starting) And StringInStr($String, $Ending) Then $StL = StringTrimLeft($String, StringInStr($String, $Starting) - 1) $SeL = StringLeft($StL, StringInStr($StL, $Ending) + 1) $StringBetween = StringTrimLeft(StringTrimRight($SeL, StringLen($Ending)), StringLen($Starting)) Return $StringBetween Else Return 0 EndIf EndFunc $sFilePath = FileOpenDialog ( "Select HTML file to strip.", "My Computer", "HTML (*.html)|HTM (*.htm)" , 1 ) $sFileContent = FileRead($sFilePath) $sWorkVar = $sFileContent While 1 $sWorkVar2 = StringReplace($sWorkvar, "java script:mpd(" & $StringBetween & ");", "") _GetStringBetween($sWorkVar2, "java script:mpd(", ");") MsgBox(1,"Square", $StringBetween) WEnd Do I just need another variable for every value I want to post? And if so, could I just make an array for every value there is? Edited February 18, 2006 by Flawblure Link to comment Share on other sites More sharing options...
Valuater Posted February 18, 2006 Share Posted February 18, 2006 1 does this "java script:mpd(" only show ONE time on the HTML page 2 do you need to do this in "Real Time" 8) Link to comment Share on other sites More sharing options...
Flawblure Posted February 18, 2006 Author Share Posted February 18, 2006 1does this "java script:mpd("only show ONE time on the HTML page2do you need to do this in "Real Time"8)java script:mpd( can be shown up to 37 times on the page. And its for a game... so the values between java script:mpd( and ); are constantly changing. Not sure what you mean by real time. When it's finished and working I'll replace with reading it from a file to directly from the website. Link to comment Share on other sites More sharing options...
Valuater Posted February 18, 2006 Share Posted February 18, 2006 (edited) real time read the web page you are on ... find the statments "java script:mpd( " and use the info right then?? 8) if that is true we could work from that direction Edited February 18, 2006 by Valuater Link to comment Share on other sites More sharing options...
Flawblure Posted February 18, 2006 Author Share Posted February 18, 2006 real timeread the web page you are on ...find the statments "java script:mpd( "and use the info right then??8)if that is true we could work from that directionYes, that is correct. I attached basically what I'd be reading everytime it scanned it in my first post. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 18, 2006 Moderators Share Posted February 18, 2006 Was that me???... lol8)It was your thread, but by no means directed toward your thread ... but does/did pertain to this one. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 18, 2006 Moderators Share Posted February 18, 2006 K, I got a loop for it going now, but it only takes 2 values. Global $StringBetween Func _GetStringBetween($String, $Starting, $Ending) If StringInStr($String, $Starting) And StringInStr($String, $Ending) Then $StL = StringTrimLeft($String, StringInStr($String, $Starting) - 1) $SeL = StringLeft($StL, StringInStr($StL, $Ending) + 1) $StringBetween = StringTrimLeft(StringTrimRight($SeL, StringLen($Ending)), StringLen($Starting)) Return $StringBetween Else Return 0 EndIf EndFunc $sFilePath = FileOpenDialog ( "Select HTML file to strip.", "My Computer", "HTML (*.html)|HTM (*.htm)" , 1 ) $sFileContent = FileRead($sFilePath) $sWorkVar = $sFileContent While 1 $sWorkVar2 = StringReplace($sWorkvar, "java script:mpd(" & $StringBetween & ");", "") _GetStringBetween($sWorkVar2, "java script:mpd(", ");") MsgBox(1,"Square", $StringBetween) WEnd Do I just need another variable for every value I want to post? And if so, could I just make an array for every value there is? The way you have that $sWorkVar outside the loop, I don't think your information will ever change... you'd have to FileRead() inside the loop to get any changes (current information) otherwise your just reading the same thing over and over, maybe set up a timer for it or something. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Flawblure Posted February 18, 2006 Author Share Posted February 18, 2006 The way you have that $sWorkVar outside the loop, I don't think your information will ever change... you'd have to FileRead() inside the loop to get any changes (current information) otherwise your just reading the same thing over and over, maybe set up a timer for it or something.Putting the ReadFile inside the loop doesnt change a thing. It still just displays a message box for -2,-2 and then -1,-2 and then loops that. Link to comment Share on other sites More sharing options...
Valuater Posted February 18, 2006 Share Posted February 18, 2006 here is an effort expandcollapse popup#include <file.au3> #include <IE.au3> Dim $x, $Count, $Move[100] $oIE = _IECreate() _IENavigate($oIE, "http://www.autoitscript.com/"); need your web site here $sloc = @TempDir & "\Htmltext.txt" $Body = _IEBodyReadHTML($oIE) FileDelete($sloc) FileWrite($sloc, $Body) Dim $aRecords If Not _FileReadToArray( $sloc, $aRecords) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) Exit EndIf For $x = 1 to $aRecords[0] If StringInStr($aRecords[$x], "java script:mpd(") Then $Count = $Count + 1 $Move[$Count] = _GetStringBetween($aRecords[$x], "java script:mpd(", ")") MsgBox(0,"Move #" & $Count, $Move[$Count]) ; what do do next with the info???????????? EndIf Next Func _GetStringBetween($String, $Starting, $Ending) If StringInStr($String, $Starting) And StringInStr($String, $Ending) Then $StL = StringTrimLeft($String, StringInStr($String, $Starting) - 1) $SeL = StringLeft($StL, StringInStr($StL, $Ending) + 1) $StringBetween = StringTrimLeft(StringTrimRight($SeL, StringLen($Ending)), StringLen($Starting)) Return $StringBetween Else Return 0 EndIf EndFunc 8) Link to comment Share on other sites More sharing options...
Flawblure Posted February 18, 2006 Author Share Posted February 18, 2006 here is an effort #include <file.au3> #include <IE.au3> Dim $x, $Count, $Move[100] $oIE = _IECreate() _IENavigate($oIE, "http://www.autoitscript.com/"); need your web site here $sloc = @TempDir & "\Htmltext.txt" $Body = _IEBodyReadHTML($oIE) FileDelete($sloc) FileWrite($sloc, $Body) Dim $aRecords If Not _FileReadToArray( $sloc, $aRecords) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) Exit EndIf For $x = 1 to $aRecords[0] If StringInStr($aRecords[$x], "java script:mpd(") Then $Count = $Count + 1 $Move[$Count] = _GetStringBetween($aRecords[$x], "java script:mpd(", ")") MsgBox(0,"Move #" & $Count, $Move[$Count]) ; what do do next with the info???????????? EndIf Next Func _GetStringBetween($String, $Starting, $Ending) If StringInStr($String, $Starting) And StringInStr($String, $Ending) Then $StL = StringTrimLeft($String, StringInStr($String, $Starting) - 1) $SeL = StringLeft($StL, StringInStr($StL, $Ending) + 1) $StringBetween = StringTrimLeft(StringTrimRight($SeL, StringLen($Ending)), StringLen($Starting)) Return $StringBetween Else Return 0 EndIf EndFunc 8) Works perfectly!! THANKS!!! Link to comment Share on other sites More sharing options...
Valuater Posted February 18, 2006 Share Posted February 18, 2006 Welcome!! 8) Link to comment Share on other sites More sharing options...
Flawblure Posted February 18, 2006 Author Share Posted February 18, 2006 Alright, I know I'm asking alot, but once it reads the data in, can I then take all of the value's gotten from the mpd:( ) stuff, and put them into a big 2 dimensional array? Say, I have these values after reading the site. (-2,-2) (-1,-2) (0,-2) (1,-2) (-2,-1) (-1,-1) (0,-1) (1,-1) (2,-1) (-2,0) (-1,0) (0,0) (1,0) (2,0) (3,0) (-2,1) (-1,1) (0,1) (1,1) (2,1) (3,1) (-1,2) (0,2) (1,2) (2,2) (3,2) (0,3) (1,3) (2,3) (3,3) Could I then make an array called something like $SquareCoord[$i][$x] and automatically read in all the values into it? So that $i would be which coord it was, and then $x would be either the x value of it, or the y value of it? So... in the list I show there, (1, -2), which is the third down on the list, would be: $SquareCoord[3][1] to get the X value, or in this case, 1, and $SquareCoord[3][2] to get the Y value, in this case, -2? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 18, 2006 Moderators Share Posted February 18, 2006 You could always use StringSplit() here, are the numbers actually placed like that with the brackets and comma? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. 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