find() 方法不适用于标签内的元素<svg>



我目前正在尝试抓取一个网站,所需的数据在<svg>标签中。我尝试使用bs4模块的find()方法,但它不起作用。我还能尝试什么?

SVG数据样本

<svg height="24" width="48" class="timer">
<rect x="0.75" y="0.75" height="22.5" width="46.5" 
class="main_rect"></rect>
<text x="24.25" y="12.25" class="text">Some text</text>
<rect x="0.75" y="0.75" height="22.5" width="46.5" class="progress_rect">
</svg>

我需要获得<text>标记,但find()方法不起作用。

page2 ='<svg height="24" width="48" class="timer"><rect x="0.75" y="0.75" height="22.5" width="46.5" class="main_rect"></rect><text x="24.25" y="12.25" class="text">Some text</text><rect x="0.75" y="0.75" height="22.5" width="46.5" class="progress_rect"></svg>'


soup = BeautifulSoup(page2, "html.parser")





print(soup.select('text.text')[0].text)

C:/Users/KT_LAB/Desktop/test/kakao.py
Some text

使用select怎么样?

最新更新