我在使用漂亮汤方面很新,在一个支架后提取文字有点困难。
<span content>"text"
<img content src="/assets/images/photo.png">"Text I would like to grab"
<span content class="classname">Text</span>
</span>我试图在照片后提取文本,但我似乎无法抓住它。谁能给我指明正确的方向
非常感谢:)
发布于 2022-09-14 05:52:17
您可以通过查找元素find_next标记和提取文本来使用img方法。
from bs4 import BeautifulSoup
soup=BeautifulSoup(html,"html.parser")
text1=soup.find("img").find_next(text=True).strip()输出:
'"Text I would like to grab"'https://stackoverflow.com/questions/73711993
复制相似问题