How to load next page in xpath

For the plugin on Break.com I load all the videos from a particular page using xpath.



However on that page there are only 12 video’s shown and the rest can be found using the next button. The url structure of the next button is http://sitename.com/1 and plus 1 till the final page is reached.



How could I create a loop loading all pages and videos in one page on plex?



The code for loading the video’s of one page is shown below.



def Video(sender, url):<br />
<br />
  dir = MediaContainer(title3=sender.itemTitle, art=R(ART), viewGroup="InfoList")<br />
<br />
  videos = XML.ElementFromURL(url, isHTML=True, errors='ignore').xpath(XPATH_VIDEOS)<br />
  for content in videos:<br />
    title = content.xpath("./a/span")[0].text<br />
    thumb = content.xpath("./a/img")[0].get('src')<br />
    summary = content.xpath("./a")[0].get('title')<br />
    url = content.xpath("./a")[0].get('href')<br />
    dir.Append(Function(VideoItem(PlayVideo, title=title, summary=summary, thumb=thumb), url=url))<br />
<br />
  return dir

Use recursion. Something like:



<br />
def Video(sender, url, page=1):<br />
<br />
  dir = MediaContainer(title3=sender.itemTitle, art=R(ART), viewGroup="InfoList")<br />
  pagedUrl = url + page<br />
  videos = XML.ElementFromURL(pagedUrl, isHTML=True, errors='ignore').xpath(XPATH_VIDEOS)<br />
  for content in videos:<br />
    title = content.xpath("./a/span")[0].text<br />
    thumb = content.xpath("./a/img")[0].get('src')<br />
    summary = content.xpath("./a")[0].get('title')<br />
    url = content.xpath("./a")[0].get('href')<br />
    dir.Append(Function(VideoItem(PlayVideo, title=title, summary=summary, thumb=thumb), url=url))<br />
  if [are there more pages xpath]:<br />
    dir.Append(Function(DirectoryItem(Video, title="More..."), url=url, page=page+1))<br />
  return dir<br />




Note the extra page number parameter to the method and the construction of a paged url from the parameters. I guess that'll mean the url passed will change slightly (strip '/1'). You'll need to detect whether the page has a 'next' navigation link and use in the if statement to determine if the More .. is added.

Also, as a general note. These constructs are used throughout the existing plugins. You can learn a lot by looking at the existingn code.

Jonny

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.