本文整理汇总了Python中variety.Util.Util.safe_map方法的典型用法代码示例。如果您正苦于以下问题:Python Util.safe_map方法的具体用法?Python Util.safe_map怎么用?Python Util.safe_map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类variety.Util.Util
的用法示例。
在下文中一共展示了Util.safe_map方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_for_author
# 需要导入模块: from variety.Util import Util [as 别名]
# 或者: from variety.Util.Util import safe_map [as 别名]
def get_for_author(self, author):
logger.info(lambda: "Fetching quotes from Goodreads for author=%s" % author)
url = iri2uri(u"https://www.goodreads.com/quotes/search?utf8=\u2713&q=%s" % author)
soup = Util.html_soup(url)
page_links = list(Util.safe_map(int,
[pagelink.contents[0] for pagelink in
soup.find_all(href=re.compile('quotes/search.*page='))]))
if page_links:
page = random.randint(1, max(page_links))
url = iri2uri(u"https://www.goodreads.com/quotes/search?utf8=\u2713&q=%s&page=%d" % (author, page))
soup = Util.html_soup(url)
return self.get_from_soup(url, soup)
示例2: get_for_keyword
# 需要导入模块: from variety.Util import Util [as 别名]
# 或者: from variety.Util.Util import safe_map [as 别名]
def get_for_keyword(self, keyword):
logger.info(lambda: "Fetching quotes from Goodreads for keyword=%s" % keyword)
url = iri2uri(u"https://www.goodreads.com/quotes/tag?utf8=\u2713&id=%s" % keyword)
soup = Util.html_soup(url)
page_links = list(Util.safe_map(int,
[pagelink.contents[0] for pagelink in
soup.find_all(href=re.compile('quotes/tag.*page='))]))
if page_links:
page = random.randint(1, max(page_links))
url = iri2uri(u"https://www.goodreads.com/quotes/tag?utf8=\u2713&id=%s&page=%d" % (keyword, page))
soup = Util.html_soup(url)
return self.get_from_soup(url, soup)
示例3: test_safe_map
# 需要导入模块: from variety.Util import Util [as 别名]
# 或者: from variety.Util.Util import safe_map [as 别名]
def test_safe_map(self):
def f(i):
if i <= 10: raise Exception
return i
self.assertEquals([20,30], list(Util.safe_map(f, [1,5,20,10,30,4])))