Yam*_*088 -1 regex bash perl grep curl
我需要解析HTML文件并删除除锚标记之外的所有内容.例如:
<html>
<body>
<p>boom</p>
<a href="/blah" rel="no-follow">Example</a>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我只需要保持:
<a href="/blah" rel="no-follow">Example</a>
Run Code Online (Sandbox Code Playgroud)
我正在使用cURL来检索html和我发现的一小段代码,除了标签的锚文本之外.这就是我正在使用的:
curl http://www.google.com 2>&1 | perl -pe 's/\<.*?\>//g'
Run Code Online (Sandbox Code Playgroud)
有一个简单的命令行方式来做到这一点?我的最终目标是将其放入bash脚本并执行它.我很难理解正则表达式和perl.
使用Mojolicious
命令行工具mojo
:
mojo get http://www.google.com 'a'
Run Code Online (Sandbox Code Playgroud)
输出:
<a class="gb1" href="http://www.google.com/imghp?hl=en&tab=wi">Images</a>
<a class="gb1" href="http://maps.google.com/maps?hl=en&tab=wl">Maps</a>
<a class="gb1" href="https://play.google.com/?hl=en&tab=w8">Play</a>
<a class="gb1" href="http://www.youtube.com/?tab=w1">YouTube</a>
<a class="gb1" href="http://news.google.com/nwshp?hl=en&tab=wn">News</a>
<a class="gb1" href="https://mail.google.com/mail/?tab=wm">Gmail</a>
<a class="gb1" href="https://drive.google.com/?tab=wo">Drive</a>
<a class="gb1" href="http://www.google.com/intl/en/options/" style="text-decoration:none"><u>More</u> »</a>
<a class="gb4" href="http://www.google.com/history/optout?hl=en">Web History</a>
<a class="gb4" href="/preferences?hl=en">Settings</a>
<a class="gb4" href="https://accounts.google.com/ServiceLogin?hl=en&continue=http://www.google.com/" id="gb_70" target="_top">Sign in</a>
<a href="/chrome/index.html?hl=en&brand=CHNG&utm_source=en-hpp&utm_medium=hpp&utm_campaign=en" onclick="google.promos&&google.promos.toast&& google.promos.toast.cl()">Install Google Chrome</a>
<a href="/advanced_search?hl=en&authuser=0">Advanced search</a>
<a href="/language_tools?hl=en&authuser=0">Language tools</a>
<a href="http://www.google.com/chrome/devices/index.html" onclick="google.promos&&google.promos.link&& google.promos.link.cl()">Chromebook: For students</a>
<a href="/intl/en/ads/">Advertising Programs</a>
<a href="/services/">Business Solutions</a>
<a href="https://plus.google.com/116899029375914044550" rel="publisher">+Google</a>
<a href="/intl/en/about.html">About Google</a>
<a href="/intl/en/policies/">Privacy & Terms</a>
Run Code Online (Sandbox Code Playgroud)
如需有用的8分钟介绍性视频,请查看:Mojocast第5集