From d5f41bf37ce2a649cfa182e40c4205fe02edb4f5 Mon Sep 17 00:00:00 2001 From: RicterZ Date: Sun, 15 Mar 2020 00:41:40 +0800 Subject: [PATCH] fix bug of --tag in python2.7 --- nhentai/parser.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/nhentai/parser.py b/nhentai/parser.py index 0c43882..97ea354 100644 --- a/nhentai/parser.py +++ b/nhentai/parser.py @@ -1,10 +1,9 @@ # coding: utf-8 from __future__ import unicode_literals, print_function +import sys import os import re -import threadpool -import requests import time from bs4 import BeautifulSoup from tabulate import tabulate @@ -105,6 +104,7 @@ def favorites_parser(page_range=''): return result + def page_range_parser(page_range, max_page_num): pages = set() ranges = str.split(page_range, ',') @@ -130,6 +130,7 @@ def page_range_parser(page_range, max_page_num): return list(pages) + def doujinshi_parser(id_): if not isinstance(id_, (int,)) and (isinstance(id_, (str,)) and not id_.isdigit()): raise Exception('Doujinshi id({0}) is not valid'.format(id_)) @@ -232,7 +233,12 @@ def tag_parser(tag_name, sorting='date', max_page=1, index=0): sorting = '' for p in range(1, max_page + 1): - if isinstance(tag_name, str): + if sys.version_info >= (3, 0, 0): + unicode_ = str + else: + unicode_ = unicode + + if isinstance(tag_name, (str, unicode_)): logger.debug('Fetching page {0} for doujinshi with tag \'{1}\''.format(p, tag_name)) response = request('get', url='%s/%s/%s?page=%d' % (constant.TAG_URL[index], tag_name, sorting, p)).content result += _get_title_and_id(response)