Chainsaw 9 Posted September 1, 2017 Report Share Posted September 1, 2017 I'm trying to scrape the first result from a list of results on a page. At the moment I'm scraping the matching attribute into a list and then grabbing the first item from that list. Seems a little redundant. I'm wondering if there is an easy way to just grab the first matching result and ignore the rest? When I scrape the attribute I get a list like this. item1item2item3item4..item500item501 I'm putting that into a list with $new_line as the delimiter and then using $list_item to get the first item. What would be a better way to do this? Quote Link to post Share on other sites
pash 504 Posted September 2, 2017 Report Share Posted September 2, 2017 tryhttp://wiki.ubotstudio.com/wiki/Element_Offset Quote Link to post Share on other sites
Code Docta (Nick C.) 638 Posted September 2, 2017 Report Share Posted September 2, 2017 You can just use "$list item" position 0 then clear the list.. Quote Link to post Share on other sites
Chainsaw 9 Posted September 6, 2017 Author Report Share Posted September 6, 2017 Thanks pash and Code Docta. Yes I've found I have to use something like this set(#itemName,$list item($list from text($scrape attribute(<innertext=w"*">,"innertext"),$new line),0),"Global") It would be handy if there were a simple scrap option that only returned the first matching item. Quote Link to post Share on other sites
HelloInsomnia 1103 Posted September 6, 2017 Report Share Posted September 6, 2017 It would be handy if there were a simple scrap option that only returned the first matching item. Pash already pointed you to the function that does that - element offset will return the element at the offset you desire. So if you want the first then the offset would be 0. So your code most likely would be: set(#itemName,$scrape attribute($element offset(<innertext=w"*">,0),"innertext"),"Global") Quote Link to post Share on other sites
Chainsaw 9 Posted September 7, 2017 Author Report Share Posted September 7, 2017 Yes that does work. However it is unfortunate the default action doesn't take the first matching result rather than the last matching result. It would also be better if element offset didn't have to be manually edited into the code. If there is more than one matching result, surely an option to specify the offset should automatically appear. Quote Link to post Share on other sites
HelloInsomnia 1103 Posted September 7, 2017 Report Share Posted September 7, 2017 Yes that does work. However it is unfortunate the default action doesn't take the first matching result rather than the last matching result. It would also be better if element offset didn't have to be manually edited into the code. If there is more than one matching result, surely an option to specify the offset should automatically appear. What do you mean by "the default action doesn't take the first matching result rather than the last matching result?" And I see this a lot people want specific answers to solve their problems but it's much better for everyone if they are more general like this because that way they are way more flexible. If Ubot had created more specific implementations then perhaps we wouldn't be able to solve this problem so easily. There won't always be one single function to do the job, that is why functions are stack-able like this so that we can put together these more general implementations to create our own specific ones. Quote Link to post Share on other sites
Chainsaw 9 Posted September 7, 2017 Author Report Share Posted September 7, 2017 In most use cases the 1st matching result is probably the one that is needed. The last matching result of a table for example is unlikely to be the result needed but this is the default result returned. Quote Link to post Share on other sites
HelloInsomnia 1103 Posted September 8, 2017 Report Share Posted September 8, 2017 In most use cases the 1st matching result is probably the one that is needed. The last matching result of a table for example is unlikely to be the result needed but this is the default result returned. Can you show me an example of what you mean, I almost feel like were talking about two different things. Quote Link to post Share on other sites
Chainsaw 9 Posted September 14, 2017 Author Report Share Posted September 14, 2017 Unfortunately it's inside a private members area. Maybe its something weird about the site's code as its a browser based SAAS. 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.