Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在Beautifulsoup4中找到明文兄弟姐妹?_Python_Python 3.x_Beautifulsoup - Fatal编程技术网

Python 如何在Beautifulsoup4中找到明文兄弟姐妹?

Python 如何在Beautifulsoup4中找到明文兄弟姐妹?,python,python-3.x,beautifulsoup,Python,Python 3.x,Beautifulsoup,例如: 我在一个段落元素中 我是纯文本! 我怎样才能得到我是纯文本文本 我已经试过了: 从bs4导入美化组 soup=BeautifulSoup(“…”,“html.parser”) soup.find(“p”).findNextSibling() #不返回 调用。使用参数text=True查找下一个兄弟姐妹(): txt = ''' <p>I am in a paragraph element!</p> I am plaintext!''' from bs4 im

例如:

我在一个段落元素中

我是纯文本!
我怎样才能得到
我是纯文本find(“p”)
在BeautifulSoup 4中编码>文本

我已经试过了:

从bs4导入美化组
soup=BeautifulSoup(“…”,“html.parser”)
soup.find(“p”).findNextSibling()
#不返回

调用
。使用参数
text=True查找下一个兄弟姐妹()

txt = '''
<p>I am in a paragraph element!</p>

I am plaintext!'''

from bs4 import BeautifulSoup

soup = BeautifulSoup(txt, 'html.parser')

print(soup.find('p').find_next_sibling(text=True))

你能和周围的元素分享一个例子吗?
I am plaintext!