我希望获取一个URL并使用Applescript排除一个单词

时间:2015-01-29 11:03:00

标签: macos curl grep applescript

我需要脚本帮助。我想抓取一个网址并排除一个字词。 “mydomaingoeshere”下面的单词,是你填写完整网址的地方。例如,如果我从URL中提取标题,我想从标题中排除我想要的任何单词。

do shell script "curl mydomaingoeshere/ | grep -i \"<title>\""

1 个答案:

答案 0 :(得分:0)

所以,如果我这样做:

curl www.google.com

我明白了

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.co.uk/?gfe_rd=cr&amp;ei=ExnKVMbHKMbEaJ7hgOAC">here</A>.
</BODY></HTML>

但是,如果出于某种原因,我不喜欢单词TITLE,我会这样做:

curl www.google.com | sed 's/TITLE//g'

使用sed替换/替换(s)单词TITLE(或第一对//之间发生的任何内容)什么都没有(出现在第二对//)全局(g),无论它出现在任何一行

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<>302 Moved</></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.co.uk/?gfe_rd=cr&amp;ei=vRnKVLffGMjDaNnFgeAI">here</A>.
</BODY></HTML>

如果您正在查看您提到的词典网站,并希望获取 HTML TITLE ,但删除Findtheand:< / p>

curl dictionary.reference.com | grep -i "<title>" | sed -E 's/Find|the|and//g'

您需要额外的-E来表示您希望能够使用|来指定替换。

相关问题