本文整理汇总了Python中src.tools.match.Match.jianshu_author方法的典型用法代码示例。如果您正苦于以下问题:Python Match.jianshu_author方法的具体用法?Python Match.jianshu_author怎么用?Python Match.jianshu_author使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类src.tools.match.Match
的用法示例。
在下文中一共展示了Match.jianshu_author方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_work_set
# 需要导入模块: from src.tools.match import Match [as 别名]
# 或者: from src.tools.match.Match import jianshu_author [as 别名]
def create_work_set(self, target_url):
u"""
根据target_url(例:http://www.jianshu.com/users/b1dd2b2c87a8/latest_articles)的内容,
先获得creator_id, 再根据文章的数目, 获得页面数, 依次打开每个页面, 将文章的地址放入work_set中
:param target_url:
:return:
"""
if target_url in self.task_complete_set:
return
id_result = Match.jianshu_author(target_url)
jianshu_id = id_result.group('jianshu_id')
article_num, article_list = self.get_jianshu_question_list(target_url)
self.task_complete_set.add(target_url)
if article_num % 9 != 0:
page_num = article_num/9 + 1 # 9 href on one page
else:
page_num = article_num / 9
for item in article_list:
self.work_set.add(item)
for page in range(page_num-1): # page+2, don't need to get the first page
url = 'http://www.jianshu.com/users/{}/latest_articles?page={}'.format(jianshu_id, page+2)
content_article_list = Http.get_content(url)
article_list = self.parse_get_article_list(content_article_list)
for item in article_list:
self.work_set.add(item)
return
示例2: parse_jianshu_author
# 需要导入模块: from src.tools.match import Match [as 别名]
# 或者: from src.tools.match.Match import jianshu_author [as 别名]
def parse_jianshu_author(command):
u"""
:param command: homepage of someone, e.g. http://www.jianshu.com/users/b1dd2b2c87a8/latest_articles
:return: task:
"""
result = Match.jianshu_author(command)
jianshu_id = result.group('jianshu_id')
task = SingleTask()
task.author_id = jianshu_id
task.kind = 'jianshu_author'
task.spider.href = 'http://www.jianshu.com/users/{}/latest_articles'.format(jianshu_id)
task.book.kind = 'jianshu_author'
task.book.sql.info_extra = 'creator_id = "{}"'.format(jianshu_id)
task.book.sql.article_extra = 'author_id = "{}"'.format(jianshu_id)
task.book.author_id = jianshu_id
return task