【发布时间】:2014-10-10 09:17:04
【问题描述】:
目前我有以下代码:
author_name = soup.find(True, {"class":["author", "author-name"]})
if author_name is not None:
print author_name.text
else:
author_name = soup.find(rel="author")
if author_name is not None:
print author_name.text
else:
print "No Author Found"
我正在寻找一篇文章的作者。因此,我在类中查找 class="author"、class="author-name" 等条目或 rel=author 等条目。如果我按照我的方式进行操作,最终会出现很多不同的if 和else 语句。这对我来说似乎不是很优雅,即使我最近才开始编码。你们能帮我看看如何更优雅地做到这一点吗?
【问题讨论】:
标签: python web-scraping beautifulsoup data-extraction