Jump to content
UBot Underground

passing a list back from a function?


Recommended Posts

Hey guys... got a issue that im sure can be easy solved from the experts here

 

I've wrote a function that take 2 params and does some custom scraping of a page and 

I want to pass the result back as a list. 

 

define $GetAllUrls(#siteurl#basedomain) {
    set(#siteurl#siteurl"Local")
    set(#basedomain#basedomain"Local")
    navigate(#siteurl"Wait")
    wait for browser event("Everything Loaded""")
    // custom scrape code here        wait(1)
    }
    return(%urlListLocal)
}

 

I get errors when i want to assign the variable to a list or a string.. Tried the 2 following ways but both still get errors

 

1) add list to list(%urlList$GetAllUrls(#tmpUrl#currentUrl), "Delete""Global")

 

2) tried to set a generic var then convert to a list

set(#NEWLIST$GetAllUrls(#tmpUrl#currentUrl),"Global")
add list to list(%urlList#NEWLIST"Delete""Global")

 

I've searched the forums + the docs / youtube videos but nothing covers this in any depth

and only show the returning of a single simple variable type.

Link to post
Share on other sites

as far as I know the "return" must return a variable not a list :)then you use that variable to make a list (if you have multiple lines in the variable you better write the variable in a temp file then create the list from that file in this way you will have elements of the list made from every line in the file, if you just add the variable to the list you will have one list element with all the lines in it not separate elements) ... This "solution" is just from looking very fast at your code, I did not tested it so it may not be what you need :)

Link to post
Share on other sites

I have looked over your code ... :) I think that this is what it should look like so you could use it:

set(#siteurl, "some url", "Global")
set(#basedomain, "some domain", "Global")
clear list(%urlList)
set(#Result_from_function, $GetAllUrls(#siteurl, #basedomain), "Global")
save to file("{$special folder("Application")}\\scrapeTMP", #Result_from_function)
add list to list(%urlList, $list from file("{$special folder("Application")}\\scrapeTMP"), "Delete", "Global")
define $GetAllUrls(#siteurl, #basedomain) {
    set(#siteurl, #siteurl, "Local")
    set(#basedomain, #basedomain, "Local")
    navigate(#siteurl, "Wait")
    wait for browser event("Everything Loaded", "")
    comment("put your code that will scrape the page here
This code will put the results in a \"#scrapeResult\" variable")
    set(#scrapeResult, "this is the result of the scrape code", "Global")
    return(#scrapeResult)
}

Link to post
Share on other sites

set(#NEWLIST$GetAllUrls(#tmpUrl#currentUrl),"Global")
add list to list(%urlList, $list from text(#NEWLIST,$new line), "Delete""Global")

 

that should work

  • Like 1
Link to post
Share on other sites

if you want to avoid the use of a tmp file you can use this code to make list items from every line of txt in a variable:

add list to list(%urlList, $list from text(#Result_from_function, $new line), "Delete", "Global")

and by the way, if you have multiple instances of an item on page and you want to keep them, when you create the list don't forget to change the "delete duplicates" setting ;)

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...