我有一个简单的脚本,它获取一个html页面,并尝试输出关键字的meta标记的内容。不知何故,它没有拾取关键字元标记的内容,即使html包含该标记。感谢您的帮助。你知道吗
url = “https://www.mediapost.com/publications/article/316086/google-facebook-others-pitch-in-app-ads-brand-s.html”
req = urllib2.Request(url=url)
f = urllib2.urlopen(req)
mycontent = f.read()
soup = BeautifulSoup(mycontent, 'html.parser')
keywords = soup.find("meta", property="keywords")
print keywords
我强烈推荐你。你知道吗
代码:
如果您正确地检查了它,那么您要查找的meta标记具有attributename而不是property,因此请将代码更改为
然后显示您需要编写的内容
输出:
使用
'lxml'
代替'html.parser'
,并使用soup.find_all
输出
相关问题 更多 >
编程相关推荐