illmill 87 Posted May 7, 2012 Report Share Posted May 7, 2012 This seems like such a simple thing, but I have literally been stuck on this all day. I have a list being created by a ui text box #current_list - which creates %current_list. Both of these are being populated with the content. I checked the debugger to make sure this was happening. Ok, so now my question. I am trying to search the content in either #current_list or the list items in %current_list. I am using $contains to determine if an element I'm scraping from the webpage is contained within either #current_list or %current_list. I have tried running the if then statement in a loop using %current_list and setting the #position at 0 and increasing increment of #position by 1 each time it loops. I have tried not using a loop and just going straight into the If/then where I use if $contains text: #current_list Text to Search For: $scrape attribute Sorry, I'm not a programmer and I only have the standard package so I don't have code view and can't paste the code here. Any ideas? I have even tried $contains text from list %current_list search for text $scrape attribute, but no matter what I do it returns false (when the list does, in fact, include what I'm searching for). I really can't figure out what I'm doing wrong and why I can't get it to follow the "then" node when the list contains what I'm looking for. Quote Link to post Share on other sites
JohnB 255 Posted May 7, 2012 Report Share Posted May 7, 2012 Are you using a ui text box or a ui text block? When you create the list from a list in the ui you need to create $list from text and use $new line as the delimeter. John Quote Link to post Share on other sites
Gogetta 263 Posted May 7, 2012 Report Share Posted May 7, 2012 I have tried running the if then statement in a loop using %current_list and setting the #position at 0 and increasing increment of #position by 1 each time it loops. I have tried not using a loop and just going straight into the If/then where I use if $contains text: #current_list Text to Search For: $scrape attribute This doesn't sound right to me. You should be using $next list item to read the next line. Upload your script to mediafire or somewhere so that I can look at it. Thanks Quote Link to post Share on other sites
Praney Behl 314 Posted May 8, 2012 Report Share Posted May 8, 2012 Maybe this is what you are after, I did a quick example. Instead of scraping an element here in this code I have added a UI text box to provide the text you are looking for in the list. I have include some comments to make it easier to understand what I am doing in the code. You can easily change it according to your needs. Here we go... comment("This is for illustration purpose only! This code contains sample illustration in response to the problem in the post: http://ubotstudio.com/forum/index.php?/topic/10176-need-help-simple-if-then-statement-involving-list/page__view__findpost__p__52445 #current list - UI Block Text - Contains the existing known list to search the scraped data from. This is further added to the list %current_list #pos - Variable to act as a list position pointer to loop through the list while finding the scrape element\'s existence in the current list. Example by: Praney Behl") ui block text("Current List", #current_list) ui text box("Sample scraped item", #sample_scraped) clear list(%current_list) add list to list(%current_list, $list from text(#current_list, $new line), "Delete", "Global") set(#pos, 0, "Global") loop($list total(%current_list)) { if($contains($list item(%current_list, #pos), #sample_scraped)) { then { alert("Scraped Element exists at list position {#pos}") } else { } } increment(#pos) } Hope it helps Cheers! Praney 4 Quote Link to post Share on other sites
illmill 87 Posted May 10, 2012 Author Report Share Posted May 10, 2012 Thanks for the responses! Praney - I was setting it up again using your script, but the part I don't get is the ui text box for sample scraped item. I actually need to compare a text (it's a username) that appears on the page open in the browser at that point in the script when I'm comparing it to my #current_list. It's not like I know ahead of time what the username will be, so I don't see how I can use a UI text box. Is there a way for me to get just the script so I can post it here? I only have the standard edition. Thanks. PS. the problem isn't getting the #current_list into an actual list %current_list. This is working fine because I checked it on the debugger. The problem is comparing the scraped element to the rest of the list and telling the bot to do one activity if that element exist in my list and do another activity if it doesn't. It would be easier to post the script, but I'm not sure how to do that. I can't post the file because there is sensitive login details there that I can't share. Quote Link to post Share on other sites
Praney Behl 314 Posted May 10, 2012 Report Share Posted May 10, 2012 Thanks for the responses! Praney - I was setting it up again using your script, but the part I don't get is the ui text box for sample scraped item. I actually need to compare a text (it's a username) that appears on the page open in the browser at that point in the script when I'm comparing it to my #current_list. It's not like I know ahead of time what the username will be, so I don't see how I can use a UI text box. Is there a way for me to get just the script so I can post it here? I only have the standard edition. Thanks. PS. the problem isn't getting the #current_list into an actual list %current_list. This is working fine because I checked it on the debugger. The problem is comparing the scraped element to the rest of the list and telling the bot to do one activity if that element exist in my list and do another activity if it doesn't. It would be easier to post the script, but I'm not sure how to do that. I can't post the file because there is sensitive login details there that I can't share. illmill, In my earlier post I mentioned :"Instead of scraping an element here in this code I have added a UI text box to provide the text you are looking for in the list." As I don't know what you are scraping, so in your code all you need to do is remove this bit and replace the variable I used with the UI text Box (#sample_scraped) with your scraped element to campare with the rest of the list in the loop. and Alerts can be killed and replaced with what you need to do with it. Hope it helps. Praney Quote Link to post Share on other sites
HarryPotter 9 Posted November 29, 2012 Report Share Posted November 29, 2012 comment("This is for illustration purpose only! This code contains sample illustration in response to the problem in the post: http://ubotstudio.com/forum/index.php?/topic/10176-need-help-simple-if-then-statement-involving-list/page__view__findpost__p__52445 #current list - UI Block Text - Contains the existing known list to search the scraped data from. This is further added to the list %current_list #pos - Variable to act as a list position pointer to loop through the list while finding the scrape element\'s existence in the current list. Example by: Praney Behl") ui block text("Current List", #current_list) ui text box("Sample scraped item", #sample_scraped) clear list(%current_list) add list to list(%current_list, $list from text(#current_list, $new line), "Delete", "Global") set(#pos, 0, "Global") loop($list total(%current_list)) { if($contains($list item(%current_list, #pos), #sample_scraped)) { then { alert("Scraped Element exists at list position {#pos}") } else { } } increment(#pos) } Hope it helps http://ubotstudio.com/forum/public/style_emoticons/default/smile.gif Cheers! http://ubotstudio.com/forum/public/style_emoticons/default/wink.gifPraney exactly what i needed to compare a value against list!!! thanks Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.