本文整理匯總了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