Need Help using your script

in
Subscribe to Need Help using your script 3 posts, 2 voices



StevenD User

Hello Mr. Sundstrom.

First, thank you for sharing this script and also for your blog. It is very thought provoking!

I have a couple of questions for you, if you don't mind. How do I identify potential candidates for your script? (and) How do I then go about writing the customized calls to the unpaginate function?

For my first question, does this script only work with sites that use 'NEXT'? I am interested in unpaginating a site that includes links to the numbered result pages, but does not provide a next link. If this script would work with numbered links that lack a 'NEXT' link, what would my custom script look like (any examples?)

Secondly, I looked at the facebook search unpagination script you have but was unable to match up the xpath statements with current search results. Does that script still work? If yes, then may I ask how you derive the id's you have in the script. I ask that since I would like to create a customized version for the site I visit.

I hope my questions are clear and I appreciate any time you provide in answering my questions! Thanks in advance, StevenD

 
Johan Sundström Script's Author

Potential candidates for unpagination is any page that was cookie-cutter-template-wise turned into multiple pages between which there are "next" links, or "page 1..N" links, of any sort. Anything you can craft an XPath expression for picking up on -- //a[.="next"] is an easy case, but it can be anything that is deterministic enough to be expressed in the language, which is very rich in its possibilities (peek at the very minimal "source code" of some of these scripts for inspiration, if you are new to it).

When I look for XPath expressions, I use Firebug's Inspect feature a lot -- open the Firebug console, click "Inspect" on top, and click on the next link. Let's say we're on page 2 right now and it comes up with an HTML structure that looks like this (a somewhat common and maybe-not-that-trivial one, for a budding XPath hacker):

<div id="comments">
  <a href="...">1</a> 2 <a href="...">3</a>
</div>

My strategy in this case will be "among all the page links, select the first one that follows a not-just-whitespace text node", which will probably work on page 1 to N-1, which happens to be all pages we need a next link from. (For a tricky case where multiple strategies are needed, craft an expression like 'how-to-do-it-on-some-pages | how-to-do-it-on-other-pages | how-to-do-it-on-yet-other-pages | ...'.)

In this case, the above comes out, for instance (untested -- if you have some example page in mind though, feel free to name its URL), id("comments")/a[(preceding-sibling::*[1])[length(normalize-space(.))>0]]

It's easy to try the expression in Firebug; just try $x('id("comments")...') in the Firebug console and see what it found. If the first node is your next link, and if that is the case on not just this page, but any page in the sequence (try the first page, one in the middle somewhere, the last but one page and the last one -- which should come up empty), and you'll probably be reasonably certain you got it right.

Facebook evolves quicker than the frequency of my visits or active use of the site; my hack has in all likelihood rotted long ago.

 
StevenD User

Thank you very much for your reply! I will certainly take a look at the scripts you listed (I didn't know we could search by tags here!)
I am going to try what you have suggested and let you know! Thanks again for your reply.