简体   繁体   English

删除 HTML 标签 python

[英]Remove HTML Tags python

I have looked everywhere for a solution to my problem, but none of them seem to work.我到处寻找解决问题的方法,但似乎没有一个有效。 Essentially, I want to know the simplest way to remove HTML tags from a string.本质上,我想知道从字符串中删除 HTML 标签的最简单方法。 For example,例如,

PriceTag = Soup.find_all(class_="text-robux-lg wait-for-i18n-format-render")
print(PriceTag)

This returns [<span class="text-robux-lg wait-for-i18n-format-render">1,250</span>] which is very much expected, but I don't know how to take 'PriceTag' and remove the HTML tags.这将返回[<span class="text-robux-lg wait-for-i18n-format-render">1,250</span>] ,这是非常值得期待的,但我不知道如何获取 'PriceTag' 并删除HTML 标签。

Try using the .text method:尝试使用.text方法:

print(PriceTag.text)

This will remove the HTML tags and extract the inner text of the selected element.这将删除 HTML 标记并提取所选元素的内部文本。

If this is a find_all , you need to use a for-loop to traverse:如果这是一个find_all ,则需要使用 for 循环来遍历:

for price_tag in PriceTag:
    print(price_tag.text)

I am not that experienced but i'll have a go at your question我没有那么有经验,但在你的问题上我会有一个 go

for price in Pricetag:
    print(price.text.strip())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM