[英]how to extract text within font tag using beautifulsoup
I am making my first program with beautifulsoup and my html file has code snippet like this 我正在使用beautifulsoup创建我的第一个程序,我的html文件包含这样的代码片段
......
......
......
<font face="verdana" size="3">5 n i D 1 C</font>
......
......
I want to extract 5 ni D 1 C
from within the <font>
tag. 我想从
<font>
标签中提取5 ni D 1 C
I am doing 我在做
ele=soup('font', face="verdana",size="3")
then ele=soup('font', face="verdana",size="3")
然后
ele.Contents()
but i am getting an error AttributeError: 'ResultSet' object has no attribute 'font'
when i do 但我得到一个错误
AttributeError: 'ResultSet' object has no attribute 'font'
当我这样做时, AttributeError: 'ResultSet' object has no attribute 'font'
print ele
output is 输出是
[<font face="verdana" size="3">5 n i D 1 C</font>]
that means it is searching correctly, please help me how to extract the given text. 这意味着它正在搜索,请帮助我如何提取给定的文本。
Thank you 谢谢
ele[0].contents[0]
u'5 n i D 1 C'
Try doing 试着做
ele[0].Contents()
instead of 代替
ele.Contents()
ele is a ResultSet and not the first result, might want to check the documentation for something that only returns the first result. ele是ResultSet而不是第一个结果,可能想要检查文档中只返回第一个结果的内容。 I'm not familiar with BeautifulSoup
我不熟悉BeautifulSoup
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.