本文共 873 字,大约阅读时间需要 2 分钟。
sed -n '/<a /p' html.txt | sed 's#<a \([^>]*\)>#--SYN--\1--FIN--#g; s/<//g; s/>//g' | \ sed 's/--SYN--/</g; s/--FIN--[^<]*</></g; s/[^<]*</</; s/--FIN--.*/>/;' | \ sed "s#<[^>]*href=\([^a-zA-Z>]*http://[^ >]*\)[^>]*># @\1@#g; s/<[^>]*>//g; s/'//g; s/@/ /g" > url.txt |
这里提取的是 <a href="http://domain/path/to/html.html"> 中的 http://domain/path/to/html.html 也就是 1、只匹配html的Tag为a的节点。 2、选择的是href的值。 3、href的值需要使用http://开头,就是说不支持相对路径。 # this script is use to dig href url from html file s/<a \([^>]*\)>/--SYN--\1--FIN--/g; s/[><]//g; s/--FIN--/>/g; s/--SYN--/</g; s/^\(.*\)$/>\1</; s/>[^<]*</></g; s#<[^>]*href=[^a-zA-Z>]*\(http://[^ >]*\)[^>]*>#@\1@#g; s/<[^>]*>//g; s/@@/\ /g; s/[>< '"@]//g; /^ *$/d; |
:a; h; s@^[^<]*<a\s*[^>]*\s*href\s*=\s*['"]*\(http://[^> "']*\)[^>]*>.*@\1@p; g; s@<[a-zA-Z/][a-zA-Z]*[^>]*>@@; t a; /<[a-zA-Z\/][a-zA-Z]*[^>]*$/{ N; b a; }; d; |
转载地址:http://elsab.baihongyu.com/