BeautifulSoup 中是否有 InnerText 等价物? [英] Is there an InnerText equivalent in BeautifulSoup?

查看:29
本文介绍了BeautifulSoup 中是否有 InnerText 等价物?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下代码:

soup = BeautifulSoup(page.read(), fromEncoding="utf-8")结果 = 汤.find('div', {'class':'flagPageTitle'})

我得到以下 html:

<div id="ctl00_ContentPlaceHolder1_Item65404" class="flagPageTitle" style=" "><span></span><p>这里有一些文字</p>

如何在没有任何标签的情况下获得 Some text here?BeautifulSoup 中是否有等效的 InnerText?

解决方案

您只需要:

result = soup.find('div', {'class' :'flagPageTitle'}).text

With the code below:

soup = BeautifulSoup(page.read(), fromEncoding="utf-8")
result = soup.find('div', {'class' :'flagPageTitle'})

I get the following html:

<div id="ctl00_ContentPlaceHolder1_Item65404" class="flagPageTitle" style=" ">
<span></span><p>Some text here</p>
</div>

How can I get Some text here without any tags? Is there InnerText equivalent in BeautifulSoup?

解决方案

All you need is:

result = soup.find('div', {'class' :'flagPageTitle'}).text

这篇关于BeautifulSoup 中是否有 InnerText 等价物?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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