Jump to content


Photo

Need Help! Simple if then statement involving list


  • Please log in to reply
6 replies to this topic

#1 illmill

illmill

    Advanced Member

  • UBot Users
  • PipPipPip
  • 379 posts
  • OS:Windows 7
  • Total Memory:8Gb
  • Framework:v3.5
  • License:Dev

Posted 07 May 2012 - 02:42 AM

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.

#2 JohnB

JohnB

    Advanced Member

  • UBot Users
  • PipPipPip
  • 3350 posts
  • LocationNJ
  • OS:Windows 7
  • Total Memory:8Gb
  • Framework:v3.5 & v4.0
  • License:Dev

Posted 07 May 2012 - 10:22 AM

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

#3 Gogetta

Gogetta

    Advanced Member

  • Moderators
  • 581 posts
  • OS:Windows Vista
  • Total Memory:4Gb
  • Framework:v3.5
  • License:Dev

Posted 07 May 2012 - 02:33 PM

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

#4 Praney Behl

Praney Behl

    Master Blaster

  • UBot Users
  • PipPipPip
  • 2371 posts
  • LocationBrisbane, Australia
  • OS:Windows 7
  • Total Memory:More Than 9Gb
  • Framework:v3.5 & v4.0
  • License:Dev

Posted 07 May 2012 - 11:56 PM

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


Complete WordPress Management Tool - WP Master Blaster
Get 100's of links from Powerful Wiki Sites : Wiki Master Blaster

The number of possibilities to do something with a tool you master, are only limited to your imagination. Try to think outside of the box.


#5 illmill

illmill

    Advanced Member

  • UBot Users
  • PipPipPip
  • 379 posts
  • OS:Windows 7
  • Total Memory:8Gb
  • Framework:v3.5
  • License:Dev

Posted 10 May 2012 - 12:01 AM

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.

#6 Praney Behl

Praney Behl

    Master Blaster

  • UBot Users
  • PipPipPip
  • 2371 posts
  • LocationBrisbane, Australia
  • OS:Windows 7
  • Total Memory:More Than 9Gb
  • Framework:v3.5 & v4.0
  • License:Dev

Posted 10 May 2012 - 12:27 AM

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


Complete WordPress Management Tool - WP Master Blaster
Get 100's of links from Powerful Wiki Sites : Wiki Master Blaster

The number of possibilities to do something with a tool you master, are only limited to your imagination. Try to think outside of the box.


#7 HarryPotter

HarryPotter

    Advanced Member

  • UBot Users
  • PipPipPip
  • 206 posts
  • OS:Windows XP
  • Total Memory:3Gb
  • Framework:unsure
  • License:Dev

Posted 28 November 2012 - 06:46 PM

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 Posted Image

Cheers! Posted Image
Praney


exactly what i needed to compare a value against list!!!

thanks :)

bots are awesome





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users