gpt4 book ai didi

python - 在 Python 中使用正则表达式从苹果商店 html 中提取应用程序的描述

转载 作者:太空宇宙 更新时间:2023-11-04 08:03:02 26 4
gpt4 key购买 nike

我需要从 Apple store html 中提取应用程序的描述。说明介于两者之间

<p itemprop="description"> DESCRIPTION HERE </p>

描述中包含一堆

符号、单词、空格等

显然 html 有很多其他文本和标签,因此需要非常精确的模式匹配。

谢谢

最佳答案

不要使用正则表达式来解析 HTML!

使用类似 BeautifulSoup! 的 HTML 解析器

>>> import bs4
>>> s = '<p itemprop="description"> DESCRIPTION HERE </p>'
>>> soup = bs4.BeautifulSoup(s, "html.parser")
>>> soup.find("p", {"itemprop": "description"}).text
>>> u' DESCRIPTION HERE '

或者如果你想找到所有元素:

>>> [item.text for item in soup.find_all("p", {"itemprop": "description"})]
>>> [u' DESCRIPTION HERE ']

关于python - 在 Python 中使用正则表达式从苹果商店 html 中提取应用程序的描述,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36706229/

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