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

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

问题描述

我的工作我的AppleScript,现在和我被困在这里..让我们这个片段为HTML code

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>

我现在需要的是没有html标签返回的单词。无论是与它的一切也许有其他的方式来格式化HTML成纯文本。

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..

结果应该是:

苹果不规矩因此苹果

Apple don't behave accordingly apple

推荐答案

如何使用<一个href=\"http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/textutil.1.html\"相对=nofollow> 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天全站免登陆