本文整理汇总了Python中page.Page.from_web_page方法的典型用法代码示例。如果您正苦于以下问题:Python Page.from_web_page方法的具体用法?Python Page.from_web_page怎么用?Python Page.from_web_page使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类page.Page
的用法示例。
在下文中一共展示了Page.from_web_page方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_source_if_matches
# 需要导入模块: from page import Page [as 别名]
# 或者: from page.Page import from_web_page [as 别名]
def get_source_if_matches(source_url, source, state, conditions=[(1, 0, 0)], fresh=False):
"""
Get a source and save it if there are matches.
min_candidates, min_constituencies, min_parties
"""
result = {
'url': source_url,
'source': source,
'state': state
}
# First, get the parsed page object
page = Page.get_url(source_url)
if page is not None:
print "Page already exists."
if not fresh:
result['skip'] = {
'text': 'Page already exists.'
}
else:
print "Page doesn't exist"
web_page = WebPage(source_url)
try:
web_page.fetch()
except WebPage.FailedToFetch, e:
result['error'] = {
'type': 'WebPage.FailedToFetch',
'text': str(e),
}
if web_page.is_local:
result['skip'] = {
'text': 'Already in cache',
}
else:
try:
page = Page.from_web_page(web_page, source)
page.save()
except Page.FetchError, e:
print "FAILED", e
result['error'] = {
'type': 'Page.FetchError',
'text': str(e),
}
示例2: get_source
# 需要导入模块: from page import Page [as 别名]
# 或者: from page.Page import from_web_page [as 别名]
print >>sys.stderr, datetime.now(), result
return result
def get_source(source_url, source, state):
"""
Get a source and save it, no matter what.
"""
web_page = WebPage(source_url)
try:
web_page.fetch()
except WebPage.FailedToFetch, e:
print "FAILED", e
return None
page = Page.from_web_page(web_page, source)
page.save()
new, article = get_or_create_doc([page])
article.process()
article.state = state
article.save()
return article