AppleScript:字符串或格式html的子字符串

AppleScript:字符串或格式html的子字符串,html,applescript,substring,cut,reformat,Html,Applescript,Substring,Cut,Reformat,我现在正在写我的applescript,我被困在这里了。。让我们以这段代码为例来说明html代码 <body><div>Apple don't behave accordingly <a href = "http://apple.com>apple</a></div></body> 苹果没有相应的行为 我现在需要的是返回不带html标记的单词。要么删除括号中的所有内容,要么有其他方法将html重新格式化为纯文本 结果应该

我现在正在写我的applescript,我被困在这里了。。让我们以这段代码为例来说明html代码

<body><div>Apple don't behave accordingly <a href = "http://apple.com>apple</a></div></body>
苹果没有相应的行为
我现在需要的是返回不带html标记的单词。要么删除括号中的所有内容,要么有其他方法将html重新格式化为纯文本

结果应该是:

苹果没有相应的行为苹果

如何使用

运行时--example(不要忘记转义引号) 从“苹果不做相应的行为”中删除标记 终点 要从someText中删除标记,请使用textutil剥离HTML 将someText设置为带引号的形式(“&someText)--伪造HTML文档标题 return(执行shell脚本“echo”&someText&“|/usr/bin/textutil-stdin-convert txt-stdout”)--strip HTML 末端移除标记
由于我遇到的问题,我想我会添加一个额外的答案。如果希望UTF-8字符不丢失,则需要:

set plain_text to do shell script "echo " & quoted form of ("<!DOCTYPE HTML PUBLIC><meta charset=\"UTF-8\">" & html_string) & space & "| textutil  -convert txt  -stdin -stdout"
set plain_text to do shell脚本“echo”&引用形式(“&html_string)&space&“textutil-convert txt-stdin-stdout”

您基本上需要添加
元标记,以确保textutil将其视为utf-8文档。

我不想搜索字符串。。我正在尝试从html代码中删除html标记。。每次代码都会不同。。
on run -- example (don't forget to escape quotes)
    removeMarkup from "<body><div>Apple don't behave accordingly <a href = \"http://apple.com\">apple</a></div></body>"
end run

to removeMarkup from someText -- strip HTML using textutil
    set someText to quoted form of ("<!DOCTYPE HTML PUBLIC>" & someText) -- fake a HTML document header
    return (do shell script "echo " & someText & " | /usr/bin/textutil -stdin -convert txt -stdout") -- strip HTML
end removeMarkup
set plain_text to do shell script "echo " & quoted form of ("<!DOCTYPE HTML PUBLIC><meta charset=\"UTF-8\">" & html_string) & space & "| textutil  -convert txt  -stdin -stdout"