danpaul23 Posted January 14, 2007 Share Posted January 14, 2007 Sorry if I'm asking too many questions but, I don't know nothing. Simply stated, I'm getting a "0" instead of the string which should be between. Here's my code: CODE#include <IE.au3> #include <String.au3> $sURL = "http://www.amazon.com/s/ref=nb_ss_b/102-5993488-0177751?url=search-alias%3Dstripbooks&field-keywords=mystery&Go.x=0&Go.y=0&Go=Go" $oIE = _IECreate($sURL) $oVar1 = _IEBodyReadHTML($oIE) $oVar2 = String($oVar1) $oVar3 = String('<td width="100%" class="searchitem" id="Td:0">') $oVar4 = String('<td width="100%" class="searchitem" id="Td:1">') $oVar5 = _StringBetween($oVar2, $oVar3, $oVar4) $oVar6 = String($oVar3) MsgBox(0,"","" & $oVar6) Link to comment Share on other sites More sharing options...
danpaul23 Posted January 14, 2007 Author Share Posted January 14, 2007 Sorry if I'm asking too many questions but, I don't know nothing. Simply stated, I'm getting a "0" instead of the string which should be between. Here's my code:CODE#include <IE.au3>#include <String.au3>$sURL = "http://www.amazon.com/s/ref=nb_ss_b/102-5993488-0177751?url=search-alias%3Dstripbooks&field-keywords=mystery&Go.x=0&Go.y=0&Go=Go"$oIE = _IECreate($sURL)$oVar1 = _IEBodyReadHTML($oIE)$oVar2 = String($oVar1)$oVar3 = String('<td width="100%" class="searchitem" id="Td:0">')$oVar4 = String('<td width="100%" class="searchitem" id="Td:1">')$oVar5 = _StringBetween($oVar2, $oVar3, $oVar4)$oVar6 = String($oVar3)MsgBox(0,"","" & $oVar6)I'm dumb, I mixed up a couple of variables but after correcting them, I still get "0" instead of the string. Probably something equally as dumb causing this. Here's the updated but still faulty code:CODE#include <IE.au3>#include <String.au3>$sURL = "http://www.amazon.com/s/ref=nb_ss_b/102-5993488-0177751?url=search-alias%3Dstripbooks&field-keywords=mystery&Go.x=0&Go.y=0&Go=Go"$oIE = _IECreate($sURL)$oVar1 = _IEBodyReadHTML($oIE)$oVar2 = String($oVar1)$oVar3 = String('<td width="100%" class="searchitem" id="Td:0">')$oVar4 = String('<td width="100%" class="searchitem" id="Td:1">')$oVar5 = _StringBetween($oVar2, $oVar3, $oVar4)$oVar6 = String($oVar5)MsgBox(0,"","" & $oVar6) Link to comment Share on other sites More sharing options...
BrettF Posted January 14, 2007 Share Posted January 14, 2007 What are you trying to do??? Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 14, 2007 Moderators Share Posted January 14, 2007 _StringBetween() Returns an Array. $sURL = "http://www.amazon.com/s/ref=nb_ss_b/102-5993488-0177751?url=search-alias%3Dstripbooks&field-keywords=mystery&Go.x=0&Go.y=0&Go=Go" $oIE = _IECreate($sURL) $oVar1 = _IEBodyReadHTML($oIE) $oVar2 = String($oVar1) $oVar3 = String('<td width="100%" class="searchitem" id="Td:0">') $oVar4 = String('<td width="100%" class="searchitem" id="Td:1">') $oVar5 = _StringBetween($oVar2, $oVar3, $oVar4) MsgBox(0,"","" & $oVar5[0]) 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...
danpaul23 Posted January 14, 2007 Author Share Posted January 14, 2007 What are you trying to do???Thanks for replying. This is almost driving me to start smoking again. I'm trying to make the html source of the page into a string and then pull a string between the two strings ($Var4 and $Var5). I know that the source string part is working but the _StringBetween function isn't giving me what is actually between ($Var4 and $Var5).Thanks again.Dan Link to comment Share on other sites More sharing options...
59FIFTY Posted January 14, 2007 Share Posted January 14, 2007 I dont know the function _StringBetween and what it does, so I cant help you. As I only can imaging you try to replace data in the html with your data? Link to comment Share on other sites More sharing options...
BrettF Posted January 14, 2007 Share Posted January 14, 2007 Maybe because _StringBetween, returns an array, use _ArrayDisplay to show them? Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
danpaul23 Posted January 14, 2007 Author Share Posted January 14, 2007 _StringBetween() Returns an Array. $sURL = "http://www.amazon.com/s/ref=nb_ss_b/102-5993488-0177751?url=search-alias%3Dstripbooks&field-keywords=mystery&Go.x=0&Go.y=0&Go=Go" $oIE = _IECreate($sURL) $oVar1 = _IEBodyReadHTML($oIE) $oVar2 = String($oVar1) $oVar3 = String('<td width="100%" class="searchitem" id="Td:0">') $oVar4 = String('<td width="100%" class="searchitem" id="Td:1">') $oVar5 = _StringBetween($oVar2, $oVar3, $oVar4) MsgBox(0,"","" & $oVar5[0]) Thanks, again for your help but when I try to run the script, I get the error message about it being a non-array variable (the last line, (MsgBox(0,"","" & $oVar5[0])), if i delet the [0], i get "0" displayed in the msgbox again. Link to comment Share on other sites More sharing options...
BrettF Posted January 14, 2007 Share Posted January 14, 2007 Havnt tested it but try: #include <IE.au3> #include <String.au3> #include <array.au3> $sURL = "http://www.amazon.com/s/ref=nb_ss_b/102-5993488-0177751?url=search-alias%3Dstripbooks&field-keywords=mystery&Go.x=0&Go.y=0&Go=Go" $oIE = _IECreate($sURL) _IELoadWait ($oIE) $oVar1 = _IEBodyReadHTML($oIE) MsgBox (0, "Values", "$oVar1 = "& @cr&$oVar1) $oVar2 = String($oVar1) $oVar3 = String('<td width="100%" class="searchitem" id="Td:0">') $oVar4 = String('<td width="100%" class="searchitem" id="Td:1">') MsgBox (0, "The Strings Shown", "$oVar3 = "&$oVar3 & @cr&"$oVar4 = "&$oVar4) $oVar5 = _StringBetween($oVar2, $oVar3, $oVar4) _ArrayDisplay($oVar5, 'The Results:') I add the _IeLoadWait, because i thought that might be the problem. Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
danpaul23 Posted January 14, 2007 Author Share Posted January 14, 2007 I dont know the function _StringBetween and what it does, so I cant help you. As I only can imaging you try to replace data in the html with your data?don't quote me on it but I think (or at least my operating assumption is that) the _stringbetween function should give you the string between two strings. i.e. _StringBetween($oVar1, $oVar2, $oVar3)my understanding (which could very well be wrong since my code isn't working... is that...$oVar1 = string to be searched$oVar2 = start string$oVar3 = end sting _StringBetween = the string between the last two variables??? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 14, 2007 Moderators Share Posted January 14, 2007 Well, I know a little bit about _StringBetween(). You are probably parsing it incorrectly. Are you sure you are trying to return all this information. Below is the result between your Start and End search by manually getting it:CODE<table border="0" width="100%" cellpadding="0" cellspacing="0"><tr valign="top"> <td><span class="resultindex">1.</span></td> <td width="100%"> <table border="0" width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"><td> <table class="n2" border="0" cellpadding="0" cellspacing="0"> <tr> <td class="imageColumn" width="88"><table border="0" cellpadding="0" cellspacing="0"> <tr><td align="center" width="80"><a href="http://www.amazon.com/Best-American-Mystery-Stories-2006/dp/0618517472/sr=1-1/qid=1168754475/ref=pd_bbs_sr_1/104-2722171-9172714?ie=UTF8&s=books"><img src="http://ec1.images-amazon.com/images/P/0618517472.01._AA90_SCTHUMBZZZ_V52729696_.jpg" width="90" alt="The Best American Mystery Stories 2006 (The Best American Series )" height="90" border="0" /></a></td><td width="8"></td></tr></table></td> <td class="dataColumn"><table cellpadding="0" cellspacing="0" border="0"><tr><td> <a href="http://www.amazon.com/Best-American-Mystery-Stories-2006/dp/0618517472/sr=1-1/qid=1168754475/ref=pd_bbs_sr_1/104-2722171-9172714?ie=UTF8&s=books"><span class="srTitle">The Best American Mystery Stories 2006 (The Best American Series )</span></a> by Scott Turow and Otto Penzler <span class="bindingBlock">(<span class="binding">Paperback</span> - Oct 11, 2006)</span></td></tr> <tr><td class="priceBlockWithTopPadding"><span class="priceType"><a href="http://www.amazon.com/Best-American-Mystery-Stories-2006/dp/0618517472/sr=1-1/qid=1168754475/ref=pd_bbs_sr_1/104-2722171-9172714?ie=UTF8&s=books">Buy new</a>: </span> <span class="listprice">$14.00</span> <span class="saleprice">$11.20</span> <span class="usedAndNewPriceBlock"><span class="priceType"> <a href="http://www.amazon.com/gp/offer-listing/0618517472/sr=1-1/qid=1168754475/ref=pd_bbs_sr_olp_1/104-2722171-9172714?ie=UTF8&s=books">Used & new</a> </span> from <span class="otherprice">$5.50</span></span></td></tr> <tr><td class="fastTrackGrid"><span class="getItBy"><a href="http://www.amazon.com/Best-American-Mystery-Stories-2006/dp/0618517472/sr=1-1/qid=1168754475/ref=pd_bbs_sr_ft_1/104-2722171-9172714?ie=UTF8&s=books">Get it by <span class="deliveryDate">January 16, 2007</span></a></span>, if you order in the next <span class="timeLeft">39 hours and 28 minutes</span>.</td></tr> <tr><td><span class="small" style="margin-left: -6px"><img src="http://ec1.images-amazon.com/images/G/01/x-locale/common/customer-reviews/stars-5-0.gif" width="64" align="absbottom" height="12" border="0" /></span></td></tr> <tr><td class="otherEditions">Other Editions: <a href="http://www.amazon.com/Best-American-Mystery-Stories-2006/dp/0618517464/sr=1-1/qid=1168754475/ref=sr_oe_1_1/104-2722171-9172714?ie=UTF8&s=books">Hardcover</a></td></tr> </table></td></tr></table> </td></tr></table></td> </tr></table></td> </tr> <tr> If you are trying to get all that information, then this will work fine:#include <array.au3> #include <inet.au3> #include <string.au3> $sURL = "http://www.amazon.com/s/ref=nb_ss_b/102-5993488-0177751?url=search-alias%3Dstripbooks&field-keywords=mystery&Go.x=0&Go.y=0&Go=Go" Dim $sStart = 'id\="Td\:0"\>', $sEnd = '\<td width\="100\%" class\="searchitem" id\="Td\:1"\>' $aArray = _StringBetween(_INetGetSource($sURL), $sStart, $sEnd, -1, 1) If IsArray($aArray) Then _ArrayDisplay($aArray, 'Found:') If you are trying to get something else, then you may need to fix your search pattern. 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...
59FIFTY Posted January 14, 2007 Share Posted January 14, 2007 If you don't know _StringBetween, don't use it You could use StringRexExp to search for a certain string between stringA and stringB, much easier Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 14, 2007 Moderators Share Posted January 14, 2007 If you don't know _StringBetween, don't use it You could use StringRexExp to search for a certain string between stringA and stringB, much easierMuch easier? What functions do you think I used to write _StringBetween()? 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...
59FIFTY Posted January 14, 2007 Share Posted January 14, 2007 By reading this Dim $sStart = 'id\="Td\:0"\>', $sEnd = '\<td width\="100\%" class\="searchitem" id\="Td\:1"\>' regular expresssion, or why else would you escape those characters, but I dont know anything about this _StringBetween function, since I dont have it. Link to comment Share on other sites More sharing options...
danpaul23 Posted January 14, 2007 Author Share Posted January 14, 2007 Havnt tested it but try: #include <IE.au3> #include <String.au3> #include <array.au3> $sURL = "http://www.amazon.com/s/ref=nb_ss_b/102-5993488-0177751?url=search-alias%3Dstripbooks&field-keywords=mystery&Go.x=0&Go.y=0&Go=Go" $oIE = _IECreate($sURL) _IELoadWait ($oIE) $oVar1 = _IEBodyReadHTML($oIE) MsgBox (0, "Values", "$oVar1 = "& @cr&$oVar1) $oVar2 = String($oVar1) $oVar3 = String('<td width="100%" class="searchitem" id="Td:0">') $oVar4 = String('<td width="100%" class="searchitem" id="Td:1">') MsgBox (0, "The Strings Shown", "$oVar3 = "&$oVar3 & @cr&"$oVar4 = "&$oVar4) $oVar5 = _StringBetween($oVar2, $oVar3, $oVar4) _ArrayDisplay($oVar5, 'The Results:') I add the _IeLoadWait, because i thought that might be the problem. Thanks again. I try to run it and don't get the display for the _Stringbetween array. I tried to put it into a msgbox and didn't get any output (not even a 0). Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 14, 2007 Moderators Share Posted January 14, 2007 By reading this Dim $sStart = 'id\="Td\:0"\>', $sEnd = '\<td width\="100\%" class\="searchitem" id\="Td\:1"\>' regular expresssion, or why else would you escape those characters, but I dont know anything about this _StringBetween function, since I dont have it.It's in the String.au3 file in the 3.2.2.0 release. It's also in the help file. 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...
danpaul23 Posted January 14, 2007 Author Share Posted January 14, 2007 Well, I know a little bit about _StringBetween(). You are probably parsing it incorrectly. Are you sure you are trying to return all this information. Below is the result between your Start and End search by manually getting it:CODE If you are trying to get all that information, then this will work fine:#include <array.au3> #include <inet.au3> #include <string.au3> $sURL = "http://www.amazon.com/s/ref=nb_ss_b/102-5993488-0177751?url=search-alias%3Dstripbooks&field-keywords=mystery&Go.x=0&Go.y=0&Go=Go" Dim $sStart = 'id\="Td\:0"\>', $sEnd = '\<td width\="100\%" class\="searchitem" id\="Td\:1"\>' $aArray = _StringBetween(_INetGetSource($sURL), $sStart, $sEnd, -1, 1) If IsArray($aArray) Then _ArrayDisplay($aArray, 'Found:') If you are trying to get something else, then you may need to fix your search pattern. Thanks for the Code. And yes, that is the information I'm trying to get. I had thought that dealing with the Html directly and just using string functions would be an easy way to tackle it. I'm about 5 days (and about as many nights) into my programing llife so I'm still stumbling around. Your code will be a steping stone for yet another branch of things to look into and try to figure out. Thanks again for your help, I really appreciate it. Link to comment Share on other sites More sharing options...
danpaul23 Posted January 14, 2007 Author Share Posted January 14, 2007 If you don't know _StringBetween, don't use it You could use StringRexExp to search for a certain string between stringA and stringB, much easierWell I'm learning so I have to try things that I don't yet know and hopefully learn from the experience. My understand is that the _StringRegExp function tells you if a given string is present within a string. How do you get it to isolate a string between two strings? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 14, 2007 Moderators Share Posted January 14, 2007 Well I'm learning so I have to try things that I don't yet know and hopefully learn from the experience. My understand is that the _StringRegExp function tells you if a given string is present within a string. How do you get it to isolate a string between two strings?Don't fret... you have one of the right functions to achieve your goal (_StringBetween()), I know others have used _IE* functions to do it for links, but it looks like you are wanting to get a multitude of information, so stick with the above. This worked as well, if you are not familiar with Regular Expressions.#include <array.au3> #include <inet.au3> #include <string.au3> $sURL = "http://www.amazon.com/s/ref=nb_ss_b/102-5993488-0177751?url=search-alias%3Dstripbooks&field-keywords=mystery&Go.x=0&Go.y=0&Go=Go" Dim $sStart = 'id="Td:0">', $sEnd = '<td width="100%" class="searchitem" id="Td:1">' $aArray = _StringBetween(_INetGetSource($sURL), $sStart, $sEnd) If IsArray($aArray) Then _ArrayDisplay($aArray, 'Found:')Where I didn't escape the characters. I tried to make _StringBetween() as universal as possible. Litteral strings for the newbies, and Regular Expressions for the power users. If you want a guide I use when I'm stuck on a regular expression (they can be tedious), you might take a look at this: http://perldoc.perl.org/perlre.html#Regular-Expressions 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...
59FIFTY Posted January 14, 2007 Share Posted January 14, 2007 (edited) Regular expressions are one of the mightiest functions to manipulate a string. As I understand your problem your about to read HTML-Code from amazon and parse it to find a certain string in it between two given strings. In RegExp this works as followed#include <Array.au3> $string = "I am some string, you're right, just some string" $aRegExp = StringRegExp($string, "I am some string(.*)just some string", 3) _ArrayDisplay($aRegExp, "StringRegExp")should display ", you're right, "so for your problem this might work#include <array.au3> #include <inet.au3> #include <string.au3> $sURL = "http://www.amazon.com/s/ref=nb_ss_b/102-5993488-0177751?url=search-alias%3Dstripbooks&field-keywords=mystery&Go.x=0&Go.y=0&Go=Go" $sHTML = _INetGetSource($sURL) $aRegExp = StringRegExp($sHTML, 'id="Td:0">(.*)<td width="100%" class="searchitem" id="Td:1">', 3) ConsoleWrite($aRegExp[0])if that's the output you need?@SmOke_NBut why make a wrapper for regexp "functions"? I know there are many newbies out there and regexp isn't quite as easy to use, but if they learn from the beginning to use it, they can achiev alot I think Edited January 14, 2007 by 59FIFTY 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