linux - 使用 sed 和正则表达式替换 html 内容

标签 linux bash web-scraping sed

我正在尝试在 bash 脚本中使用 sed 替换某些 HTML 内容。出于某种原因,我没有得到正确的结果,因为它没有替换任何东西,主要是正则表达式部分

我要替换的 HTML

<h3 class="indicate-hover css-5fzt5q">For the Most Complex Heroines Animation
<h3 class="indicate-hover css-1pvrrwb">The Psychology Behind Sibling

 head For the Most Complex Heroines Animation
 head The Psychology Behind Sibling

我用过

  sed -e 's/<h3 class="indicate-hover css-([a-b0-9]+)">/head/g'

主要是 ([a-b0-9]) 这部分执行失败,我一定是漏掉了什么,我想更具体一点,我有 "<p class="summary-class css-1azn4ub">How many words can"我想将其替换为“tail”并拥有更多其他标签。正则表达式部分让我很痛苦

最佳答案

使用sed

$ sed 's/.*-[[:alnum:]]\+">/head /' input_file

输出

head For the Most Complex Heroines Animation
head The Psychology Behind Sibling

关于linux - 使用 sed 和正则表达式替换 html 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72805436/

相关文章:

linux - 跟踪链接库

linux - shell脚本不运行

bash - -bash : [: =: unary operator expected. 当没有给出参数时

bash - 使用 Ctrl-C 终止程序而不终止父脚本

excel - 在雅虎财经中检索数据报价的 URL 问题

linux - Bash 转换多个子目录中的 PDF 文件

linux - 高效的 Linux 套接字(DMA/零拷贝)

bash - sed 匹配比预期更贪婪

python - 在 python 中抓取表

Python Selenium 将数据存储到 CSV 中的特定列?