本文整理汇总了Python中scraper.Scraper.scrapeDescr方法的典型用法代码示例。如果您正苦于以下问题:Python Scraper.scrapeDescr方法的具体用法?Python Scraper.scrapeDescr怎么用?Python Scraper.scrapeDescr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scraper.Scraper
的用法示例。
在下文中一共展示了Scraper.scrapeDescr方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_article
# 需要导入模块: from scraper import Scraper [as 别名]
# 或者: from scraper.Scraper import scrapeDescr [as 别名]
def create_article(request):
if request.method == 'POST':
form = ArticleForm(request.POST)
if form.is_valid():
if Article.objects.filter(user = request.user, url = form.cleaned_data['url']):
print >> sys.stderr, "Already posted"
response_data = {'Error': 'You have already posted this article'}
return HttpResponse(
json.dumps(response_data),
content_type="application/json"
)
try:
#Create new article
new_article = form.save(commit=False)
cleaner = urlparse(new_article.url)
cleaned_url = "http://" + cleaner.netloc + cleaner.path
new_article.url = cleaned_url
# scape info from URL
scraper = Scraper(new_article.url)
new_article.user = request.user
new_article.image, new_article.image_url = scraper.scrapeImage()
new_article.title = scraper.scrapeTitle()
new_article.site_name = scraper.scrapeSitename()
new_article.description = scraper.scrapeDescr()
new_article.pub_date = date.today()
new_article.real_pub_date = datetime.datetime.today()
new_article.save()
# adjust date
article_date = datetime.datetime.strptime(str(new_article.pub_date), '%Y-%m-%d').strftime('%b %d, %Y')
response_data = {
'article_id': new_article.id,
'article_url': new_article.url,
'article_image': new_article.image.url,
'article_title': new_article.title,
'article_site_name': new_article.site_name,
'article_user': new_article.user.username,
'article_user_id': new_article.user.id,
'article_description': new_article.description,
'article_pub_date': article_date,
}
# Success
return HttpResponse(
json.dumps(response_data),
content_type="application/json"
)
except:
response_data = {'Error': 'Error posting link. Please try again'}
return HttpResponse(
json.dumps(response_data),
content_type="application/json"
)
response_data = {'Error': 'Error posting link. Please try again'}
return HttpResponse(
json.dumps(response_data),
content_type="application/json"
)