获得使用BeautifulSoup meta标签数据 [英] Get data from the meta tags using BeautifulSoup

查看:209
本文介绍了获得使用BeautifulSoup meta标签数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想读取meta标签的描述,这是我用什么

I am trying to read the description from the meta tag and this is what I used

soup.findAll(name="description")

但它不工作,但是,code以下的工作就好了。

but it does not work, however, the code below works just fine

soup.findAll(align="center")

我如何读取元标记的描述文档的头上?

How do I read the description from the meta tag in the head of a document?

推荐答案

没错,名称不能在关键字参数的形式被用来指定命名的属性名称因为名称名称已用于 BeautifulSoup 本身。所以改用:

Yep, name can't be used in keyword-argument form to designate an attribute named name because the name name is already used by BeautifulSoup itself. So use instead:

soup.findAll(attrs={"name":"description"})

这是什么 ATTRS 参数是作为:传递作为一个字典的属性,而您不能使用关键字参数的形式,因为限制他们的名字是Python关键词或以其他方式采取BeautifulSoup本身!

That's what the attrs argument is for: passing as a dict those attribute constraints for which you can't use keyword-argument form because their names are Python keyword or otherwise taken by BeautifulSoup itself!

这篇关于获得使用BeautifulSoup meta标签数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆