From d5f257c5e6ac93f058c1c01ebe315a0a9fc395e1 Mon Sep 17 00:00:00 2001
From: ricterz <ricterzheng@gmail.com>
Date: Sat, 9 May 2015 23:33:51 +0800
Subject: [PATCH] page of search result

---
 hentai/cmdline.py |  4 +++-
 hentai/parser.py  | 12 +++++-------
 nhentai.py        |  2 +-
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/hentai/cmdline.py b/hentai/cmdline.py
index f86a20d..3d378d9 100644
--- a/hentai/cmdline.py
+++ b/hentai/cmdline.py
@@ -15,10 +15,12 @@ def banner():
 
 def cmd_parser():
     parser = OptionParser()
-    parser.add_option('--search', type='string', dest='keyword', action='store', help='keyword searched')
     parser.add_option('--download', dest='is_download', action='store_true', help='download dojinshi or not')
     parser.add_option('--id', type='int', dest='id', action='store', help='dojinshi id of nhentai')
     parser.add_option('--ids', type='str', dest='ids', action='store', help='dojinshi id set, e.g. 1,2,3')
+    parser.add_option('--search', type='string', dest='keyword', action='store', help='keyword searched')
+    parser.add_option('--page', type='int', dest='page', action='store', default=1,
+                      help='page number of search result')
     parser.add_option('--path', type='string', dest='saved_path', action='store', default='',
                       help='path which save the dojinshi')
     parser.add_option('--threads', '-t', type='int', dest='threads', action='store', default=1,
diff --git a/hentai/parser.py b/hentai/parser.py
index b48fe71..8c021e8 100644
--- a/hentai/parser.py
+++ b/hentai/parser.py
@@ -48,10 +48,10 @@ def dojinshi_parser(id):
     return dojinshi
 
 
-def search_parser(keyword):
+def search_parser(keyword, page):
     logger.debug('Searching dojinshis of keyword %s' % keyword)
     result = []
-    response = requests.get(SEARCH_URL, params={'q': keyword}).content
+    response = requests.get(SEARCH_URL, params={'q': keyword, 'page': page}).content
     html = BeautifulSoup(response)
     dojinshi_search_result = html.find_all('div', attrs={'class': 'preview-container'})
     for dojinshi in dojinshi_search_result:
@@ -62,12 +62,10 @@ def search_parser(keyword):
     return result
 
 
-def tag_parser(tag):
-    pass
-
-
 def print_dojinshi(dojinshi_list):
-    logger.log(15, 'Print Dojinshi list')
+    if not dojinshi_list:
+        return
+    logger.log(15, 'Print dojinshi list')
     print '-' * 60
     for dojinshi in dojinshi_list:
         print dojinshi['id'], '-', dojinshi['title']
diff --git a/nhentai.py b/nhentai.py
index 37c8ffe..8b52037 100644
--- a/nhentai.py
+++ b/nhentai.py
@@ -19,7 +19,7 @@ def main():
     dojinshi_list = []
 
     if options.keyword:
-        dojinshis = search_parser(options.keyword)
+        dojinshis = search_parser(options.keyword, options.page)
         if options.is_download:
             dojinshi_ids = map(lambda d: d['id'], dojinshis)
         else: