darknode 3 Posted December 10, 2013 Report Share Posted December 10, 2013 i'm running a loop to scroll the pages on twitter, and i'm trying to detect the bottom of the page so that it stops the loop.the problem i'm having is the loop continues even after the stop script command is issued. i'm assuming because the loop is running inside a define command. at the bottom of the page it says back to top, but it appears that it always says that, it's just hidden until you reach that point.can anyone help me out here in both detection of the bottom, and stopping a loop inside a define. Quote Link to post Share on other sites
the_way 52 Posted December 11, 2013 Report Share Posted December 11, 2013 you have to specify the loop to loop a certain amount of times, or you can use a loop while, and then either use a "exists" function to detect the bottom , if thats possible. or you can just use a loop while some sort of number that is being incremented on the webpage is increasing. scarpe that number and loop while it is less than 100 for example. There is normally always a divider at the bottom of a page, however, sometimes the page hangs and you never can get to the bottom, so its good to use a loop while with an either containing "exists" and an increment counter that will eventually break the loop, if there are page errors. Quote Link to post Share on other sites
darknode 3 Posted December 11, 2013 Author Report Share Posted December 11, 2013 yeah i was doing a loop 100 times, but i think i'll try that. maybe until collected is equal to or greater than expected..i didn't know if there was another way to stop a defined loop in another way like the stop script command. main reason for asking. you have to specify the loop to loop a certain amount of times, or you can use a loop while, and then either use a "exists" function to detect the bottom , if thats possible. or you can just use a loop while some sort of number that is being incremented on the webpage is increasing. scarpe that number and loop while it is less than 100 for example. There is normally always a divider at the bottom of a page, however, sometimes the page hangs and you never can get to the bottom, so its good to use a loop while with an either containing "exists" and an increment counter that will eventually break the loop, if there are page errors. Quote Link to post Share on other sites
the_way 52 Posted December 11, 2013 Report Share Posted December 11, 2013 the loop while and an increment or an exist is exactly what the stop script does, except it will break out from you loop, and then continue the rest of the program. you could use stop script, but obviously that will finish it dead. Quote Link to post Share on other sites
darknode 3 Posted December 11, 2013 Author Report Share Posted December 11, 2013 i tried loop while($comparison(#collected, ">", #total))total being the number of items that need to be collected, and collected being how many have been scraped. before the loop while i set collected to 0 so it would have a value, but the loop never starts. the loop while and an increment or an exist is exactly what the stop script does, except it will break out from you loop, and then continue the rest of the program. you could use stop script, but obviously that will finish it dead. Quote Link to post Share on other sites
the_way 52 Posted December 11, 2013 Report Share Posted December 11, 2013 so what you are saying is: loop while 0 is greater than 100 thats why it doesn't work use loop while collected < total Quote Link to post Share on other sites
darknode 3 Posted December 11, 2013 Author Report Share Posted December 11, 2013 sorry, that's what i meant. looking at it, it appears it ran, but only once for some reason, rather than continuing until the number reached the end. let me see if i can put the code in here without it getting mangled. so what you are saying is: loop while 0 is greater than 100 thats why it doesn't work use loop while collected < total Quote Link to post Share on other sites
the_way 52 Posted December 11, 2013 Report Share Posted December 11, 2013 define getfollowers { allow images("No") navigate("https://twitter.com/{#usn}/followers", "Wait") wait(10) set(#followercount, $scrape attribute(<outerhtml=w"<a class=\"js-nav\" href=\"*\" data-element-term=\"follower_stats\" data-nav=\"followers\"> <strong>*</strong> Followers </a>">, "innertext"), "Global") set(#followercount, $replace regular expression(#followercount, ",", ""), "Global") set(#fcollected, 0, "Global") loop while($comparison(#fcollected, "<", #followercount)) { wait(1) run javascript("window.scrollBy(0,11550); // horizontal and vertical scroll increments scrolldelay = setTimeout(\'pageScroll()\',10); // scrolls every 100 milliseconds") wait(1) add list to list(%data, $scrape attribute(<outerhtml=w"<span class=\"username js-action-profile-name\">*</span>">, "innertext"), "Delete", "Global") set(#followerlst, %data, "Global") increment(#fcollected) } } you had fcollected variable at the bottom changing to be the same total as the followercount. Basically you said that both should become the list total, thats why once it had reached that the loop then broke. I changed your fcollected to an increment. Quote Link to post Share on other sites
darknode 3 Posted December 11, 2013 Author Report Share Posted December 11, 2013 the fcollected is showing how many records are added at the given time, because each scroll only allows 10 or so new accounts to show up, that number is actual for the data rather than a ticker. you had fcollected variable at the bottom changing to be the same total as the followercount. Basically you said that both should become the list total, thats why once it had reached that the loop then broke. I changed your fcollected to an increment. Quote Link to post Share on other sites
the_way 52 Posted December 11, 2013 Report Share Posted December 11, 2013 just use another variable as the increment and the loop while break then. your code should have the increment at the bottom, which increases a variable number by 1. When the loop comes back round to start again, or in your case, further page down, then it will. Once that incremented variable reaches say 10, and your follower count is 10, then it will break. forget about the code inbetween the loop while. That can be anything, make sure your loop and comparison is working first, then stick your code in. if you stick your other code inside a define, it will be much easier to read to set #loopcounter= 0 loopwhile #loopcounter < #totalscraped [ page down functionscrape data and assign it to #totalscraped increment #loopcounter] something like that Quote Link to post Share on other sites
LazyBotter 188 Posted December 11, 2013 Report Share Posted December 11, 2013 I tend to use a both statement with two comparisons, one for the looping and one to check if a variable "Stop" = true/false. Then you can set up a button to set the "Stop" variable to true to stop the loop... 1 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.