本文整理汇总了Python中extractor.Extractor.extract_post_author_user_name方法的典型用法代码示例。如果您正苦于以下问题:Python Extractor.extract_post_author_user_name方法的具体用法?Python Extractor.extract_post_author_user_name怎么用?Python Extractor.extract_post_author_user_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类extractor.Extractor
的用法示例。
在下文中一共展示了Extractor.extract_post_author_user_name方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: extract_posts
# 需要导入模块: from extractor import Extractor [as 别名]
# 或者: from extractor.Extractor import extract_post_author_user_name [as 别名]
def extract_posts(self):
if self.has_soup():
raw_posts = self.soup.find_all("div", class_="entry") or []
for post in raw_posts:
#get the anchor whose href will be the post url
anchor = post.find_all("a", class_="comments")
if len(anchor) > 0 and anchor[0].has_attr("href"):
#make sure we have an absolute url
url = anchor[0]["href"] if anchor[0]["href"][:4] == "http" else "http://www.reddit.com" + anchor[0]["href"]
#make a new page to help wth extracting data
page = Page(url=url)
page.load_soup()
comments = page.extract_comments()
for comment in comments:
comment.post_url = url
users = page.extract_users()
title = page.extract_title()
extractor = Extractor(page.soup)
description = extractor.extract_post_description()
author = extractor.extract_post_author_user_name()
date = extractor.extract_post_date()
score = extractor.extract_post_score()
self.posts.append(Post(
url=url,
description=description,
comments=comments,
users=users,
author=author,
title=title,
score=score
))
break #testing only
return self.posts