gpt4 book ai didi

python - 从 标签获取值(value)

转载 作者:太空宇宙 更新时间:2023-11-04 13:54:58 24 4
gpt4 key购买 nike

如何读取值

<th class="class_name"> Sample Text </th>

任何人都可以帮助我使用 python 从上述 HTML 代码中获取字符串“示例文本”。

谢谢。

最佳答案

您可以使用 BeautifulSoup这是我最喜欢的用于解析 html 的库。

from BeautifulSoup import BeautifulSoup
html = '<th class="class_name"> Sample Text </th>'
soup = BeautifulSoup(html)
print soup.th.text

关于python - 从 <th> 标签获取值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15152398/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com