'Next Page' How to do it Please!!
#1
Hello,

I have looked around to find the exact syntax to do the 'Next Page' but i don't get it. The website im doing plugin for has two types of pagination.

1- It loads from a javascript file, this is the javascript file's link http://static.shahid.mbc.net/statics/js/...ination.js and it says in the javascript file
Quote:/* Each time the user scrolls the page,
we check to see if they have scrolled all the way down to the footer.
if so we load a new set of content blocks and append them to the list. */

This is from the website source
Quote:<!-- pagination_scroll.js includes-->
<!--<script type="text/javascript" src="http://static.shahid.mbc.net/statics/js/pagination_scroll.js"></script>-->
<script type="text/javascript">
var body_id = 'body';
var num_per_page = 10;
var num_disp_init = 15;
var scroll_loader_id = 'scroll_loader';
var channel_id = 1;
var list_id = 'filtered_list';
var top_marker_id = 'top_marker';
var offset=0;
var count = "161";
</script>

2- It's the regular pagination 1,2,3....
this is the paging div from the source
Quote: <div class='paging'>
<div class="pagination_caption">1 - 10 from 24</div>
<ul name="episode" class="page_ul pagination">


<li class="page_num active"><a href="" title="">1</a></li>
<li class="page_num"><a href="" title="">2</a></li>
<li class="page_num"><a href="" title="">3</a></li>
<li class="next nxt last"><a href="" title="">&raquo;</a></li> </ul>
</div>

This is my index2 to make it clear where is 2 regular pagination should be
Quote:def INDEX2(url):
req = urllib2.Request(url)
req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3')
data = urllib2.urlopen(req).read()
match=re.compile('</span><a href="(.+?)" title=""><b><img src="(.+?)" alt="" border="0" height="" width="" /><span class="video"></span><span class="duration">(.+?)</span></b><span class="title major"> </span><span class="title">(.+?)</span>').findall(data)
for url,thumbnail,name,duration in match:
addDir(name+' - '+duration,url,3,thumbnail)

I really appreciate any help!!
Thank you
Reply
#2
give me the adress of exact page..let me control html..also post pm please
Reply
#3
drascom Wrote:give me the adress of exact page..let me control html..also post pm please
Thank you so much drascom, i will pm you and explain everything.
Reply
#4
page navigation handled via ajax controlled script which is "http://static.shahid.mbc.net/statics/js/pagination_click.js" and it uses class to call page by trigerred clicks and rolling end of page..

and i have no idea to call that function with python.we need masters to solve it. i'm sorry...
Reply
#5
Hi, from the script you linked to -
Code:
        
            ajax_url = '/Ajax';
            ajax_url +=  '/' + 'series_sort';
            ajax_url += '?offset=' + offset;
            ajax_url += '&channel_id=' + channel_id;
            ajax_url += '&sort=' + sort;
            ajax_url += '&limit=' + num_per_page;
            
            //alert(ajax_url);
            
            new Ajax.Request (ajax_url, {        
                eval: true,
                onComplete: function(object) {
                    hide_scroll_loader (scroll_loader_id);
                    var html_response = object.responseText;
                    
                    new Insertion.Bottom ( $(list_id),  html_response )

I may be way off but it looks like you could format your own url -
Code:
    /series_sort?offset=offset&channel_id=channel_id&sort=sort&limit=num_per_page

You'll have to change the parameter values to what is needed. If you use firebug or chrome dev tools you'll likely see the request.
Reply
#6
hi divingmule,

Thank you so much for responding. The exact thing I need is I don't know how to start typing the code for "Next page", I have seen many but i don't get the steps or the syntax to start on it.

Could you please give me a little bit of your time showing the easiest steps on a quick tutorial or an example following the index2 above?

That would be really appreciated .
Reply
#7
drascom Wrote:page navigation handled via ajax controlled script which is "http://static.shahid.mbc.net/statics/js/pagination_click.js" and it uses class to call page by trigerred clicks and rolling end of page..

and i have no idea to call that function with python.we need masters to solve it. i'm sorry...

Thank you so much for trying.
Reply
#8
Code:
def INDEX2(url,page): # here you need to add the page param, the first call page would == 1
    req = urllib2.Request(url)
    req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3')
    data = urllib2.urlopen(req).read()
    match=re.compile('</span><a href="(.+?)" title=""><b><img src="(.+?)" alt="" border="0" height="" width="" /><span class="video"></span><span class="duration">(.+?)</span></b><span class="title major"> </span><span class="title">(.+?)</span>').findall(data)
    for url,thumbnail,name,duration in match:
        addDir(name+' - '+duration,url,3,thumbnail)
      
    if #something that tells you there are more pages
        add_page = page + 1
        num_per_page = 10
        offset = (page -1) * num_per_page
        channel_id = 1 # from the source you posted
        sort = # you'll need to find this variable
        ajax_url = '/Ajax'
        ajax_url +=  '/' + 'series_sort'
        ajax_url += '?offset=' + str(offset)
        ajax_url += '&channel_id=' + str(channel_id)
        ajax_url += '&sort=' + sort
        ajax_url += '&limit=' + str(num_per_page)
        # here mode is the mode used to call INDEX2, then pass add_page as the page param
        addDir('Next Page', 'http://????'+ajax_url, mode, thumbnail, add_page)
        
## To pass the page param you'll have to change def addDir()
def addDir(name,url,mode,iconimage,page):                                            
            # now add the page param to u
        u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)+"&page="+str(page)
        
## add the check for page param
try:
    url=urllib.unquote_plus(params["url"])
except:
    pass
try:
    name=urllib.unquote_plus(params["name"])
except:
    pass
try:                          
    page=int(params["page"])   # we use int here because we want a number instead of a string
except:
    pass

Hope this helps!
Reply
#9
divingmule thanks a lot, i haven't test the code yet, i was in vacation. i will work on it soon then i will let you know.

Thank you again.
Reply
#10
Hello divingmule,

I did exactly what you told me, and i added more but still i get script failed when i lunch the plugin.
I tried it too many times step by step but it didn't work.

Code:
def INDEX(url,page):
        req = urllib2.Request(url)
        req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3')
        data=urllib2.urlopen(req).read()
        match=re.compile('<a class="tip_anchor" name=".+?" href="(.+?)" title=""><b><img src="(.+?)" width="" height="" border="0" alt="" /></b><span class="title major">(.+?)</span>').findall(data)
        for url,thumbnail,name in match:
                addDir(name,url,2,thumbnail)
if # something that tells you there are more pages
        add_page = page + 1
        num_per_page = 10
        offset = (page -1) * num_per_page
        channel_id = 1 # from the source you posted
        sort = option.getAttribute('latest') # you'll need to find this variable # I added the varibale name 'latest'
        ajax_url = '/Ajax'
        ajax_url +=  '/' + 'series_sort'
        ajax_url += '?offset=' + str(offset)
        ajax_url += '&channel_id=' + str(channel_id)
        ajax_url += '&sort=' + sort
        ajax_url += '&limit=' + str(num_per_page)
        # here mode is the mode used to call INDEX2, then pass add_page as the page param
        addDir('Next Page', 'http://static.shahid.mbc.net/statics/js/pagination_click.js'+ajax_url, mode, thumbnail, add_page)
        # I dont know which link i have to put, the javascript link or the main link of the channels "http://shahid.mbc.net/media/channels"

Code:
#In this section i typed "page=None"
        params=get_params()
        url=None
        name=None
        mode=None
        page=None


Code:
#after except,try section I added this "print " "+str(page)"
        print "Mode: "+str(mode)
        print "URL: "+str(url)
        print "Name: "+str(name)
        print " "+str(page) # i don't know what have to do here.


Code:
# In the mode section I added this too "INDEX(url,page)"
        if mode==None or url==None or len(url)<1:
        print ""
        CATEGORIES()
      
        elif mode==1:
                print ""+url
                INDEX(url,page)
                
        elif mode==2:
                print ""+url
                INDEX2(url)

        elif mode==3:
                print ""+url
                VIDEOLINKS(url,name)

I don't like to give up.
Thank you
Reply
#11
Hi, if you want, http://pastebin.com or PM me your script and I will take a look.
Reply
#12
any uptate on this?
Reply

Logout Mark Read Team Forum Stats Members Help
'Next Page' How to do it Please!!1