抓取html中的所有图片,目前img标签中的已经能够拿出来了,但是还有一些是这样写的
比如
<div style="background-image:url('../image/493aid.png')"></div><div style="background-image:url(../image/493aid.png)"></div>
<div style="background:url('../image/493aid.png')"></div>
有的图片是流输出的 也是要考虑的
<body ><div id = "a"><div style="background-image:url('../image/493aid.png')"></div><div style="background-image:url(../image/491aid.png)"></div><div style="background:url('../image/492aid.png')"></div></div></body><script>var all = document.getElementById("a").innerHTML, reg = /[^\'\"\(]+(\.png|\.jpf|\.bmp)/g;console.log(all);allImg = all.match(reg);console.log(allImg);var allimg = [];all.replace(reg,function($1){ allimg.push($1);});console.log(allimg);
<body ><div id = "a"><div style="background-image:url('../image/493aid.png')"></div><div style="background-image:url(../image/491aid.png)"></div><div style="background:url('../image/492aid.png')"></div></div></body><script>var all = document.getElementById("a").innerHTML, reg = /[^\'\"\(]+(\.png|\.jpf|\.bmp)/g;console.log(all);allImg = all.match(reg);console.log(allImg);var allimg = [];all.replace(reg,function($1){ allimg.push($1);});console.log(allimg);