AppleScript:子字符串到字符串或格式 html [英] AppleScript: substring to string or format html

查看:25
本文介绍了AppleScript:子字符串到字符串或格式 html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在处理我的 applescript,但我被困在这里.. 让我们以这个片段作为 html 代码的例子

Apple 没有相应的行为

我现在需要的是返回没有 html 标签的单词.通过删除包含所有内容的括号,或者可能有任何其他方法将 html 重新格式化为纯文本..

结果应该是:

Apple 没有相应的行为 apple

解决方案

如何使用 textutil?

on run -- 示例(不要忘记转义引号)removeMarkup from "<body><div>Apple 没有相应的行为 <a href = \"http://apple.com\">apple</a></div></body>"结束运行从 someText 中删除标记 -- 使用 textutil 去除 HTML将 someText 设置为 ("<!DOCTYPE HTML PUBLIC>" & someText) 的引用形式——伪造 HTML 文档标题return (do shell script "echo " & someText & " |/usr/bin/textutil -stdin -convert txt -stdout") -- 去除 HTML结束删除标记

I'm working on my applescript right now and I'm stuck here.. Lets take this snippet as an example of html code

<body><div>Apple don't behave accordingly <a href = "http://apple.com>apple</a></div></body>

What I need now is to return the word without the html tags. Either by deleting the bracket with everything in it or maybe there is any other way to reformat html into plain text..

The result should be:

Apple don't behave accordingly apple

解决方案

How about using textutil?

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

这篇关于AppleScript:子字符串到字符串或格式 html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆