我试图从网页的html中筛选与src属性相关的链接。
我使用curl获取html和下面的sed命令来筛选url链接。
curl -s http://www.example.com/ | sed -n '/src/,/jpg/p'我的想法是过滤出以src开头,以.jpg扩展结束的行。但它不起作用,它打印出整个html。我该怎么做?
发布于 2015-04-01 10:29:21
尝试以下命令:
curl -s http://www.example.com | grep -Po '(?<=src=")[^"]*(jpg|png)'来自man grep:
-o, --only-matching
Print only the matched (non-empty) parts of a matching line,
with each such part on a separate output line.
-P, --perl-regexp
Interpret PATTERN as a Perl compatible regular expression (PCRE)查找后面的(?<=src=)断言,在字符串中的当前位置,前面是字符src=。然后,我们将寻找所有的东西,除了以jpg或png结尾的"。
https://askubuntu.com/questions/603894
复制相似问题