使用javascript从HTML网页中提取图像url
extract image url using javascript from a HTML webpage
我有一个保存为字符串的html部分的来源:
var str= '<div class="quizdisplay themestylename theme_db_primarykey">
<h1>What Power Would Suit You Best</h1>
<p class="inline_byline"">Created by <a class="url fn" href="/user/xQUANTUMNxNOVAx/profile">xQUANTUMNxNOVAx</a></p>
<div class="metacrumb">
<dl>
<dt>Tagged:</dt>
<dd><a class="tag" rel="tag" href="/tags/dark" title="dark">dark</a></dd>, <dd><a class="tag" rel="tag"
href="/tags/personality" title="personality">personality</a></dd>,
<dd><a class="tag" rel="tag" href="/tags/air"
title="air">air</a></dd>, <dd><a class="tag" rel="tag"
href="/tags/power" title="power">power</a></dd>, <dd><a class="tag"
rel="tag" href="/tags/fire" title="fire">fire</a></dd>, <dd><a
class="tag" rel="tag" href="/tags/water" title="water">water</a></dd>,
<dd><a class="tag" rel="tag" href="/tags/energy"
title="energy">energy</a></dd>, <dd><a class="tag" rel="tag"
href="/tags/earth" title="earth">earth</a></dd>, <dd><a class="tag"
rel="tag" href="/tags/lightning" title="lightning">lightning</a></dd>,
<dd><a class="tag" rel="tag" href="/tags/telekinesis"
title="telekinesis">telekinesis</a></dd>
</dl>
</div>
<div id="itemresults" class="quidget">
<p>
5493 other people got this result!
That's 34%
</p>
<a class="button viewallresults">View all results</a>
<a href="/quizzes" class="button" style="line-height:23px;width:150px;">Take another quiz!</a>
</div>
<h3 class="aquestion">Water/Ice.</h3>
<img src="/user_images/X/XQ/XQU/XQUANTUMNXNOVAX/1346304322_6798_full.jpeg"
alt="result image" />
<p>You go with the flow, following the motions of the world around you. You're calming and relaxing but have an aggressive side to
you when necessary. You can be in tune with people easily, or can be
completely cold hearted. People typically love you, and need you the
most.</p>
</div>';
如何使用javascript从这个字符串中提取图像url?
jquery
var srcArray = [];
$(str).find('img').each(function(){
src = $(this).attr('src');
srcArray.push(src);
});
或者您可以使用Regex:
var regex = /(?<=<img src=").*?(?=")/gm;
src = regex.match(str);
alert(src);
这个链接上的examle。
因为它是HTML。您可以将所有内容插入DOM(隐藏),并使用jQuery获取图像url,这有点麻烦,但可能是最简单的方法。
您也可以使用正则表达式来搜索图像标签并从中获取url。
相关文章:
- 使用javascript从HTML网页中提取图像url
- 是否可以创建一个画布来提取图像数据,而无需实际渲染画布
- 我可以使用 javascript 从类别中提取图像吗?
- 使用 AngularJS 从
RSS 提要中提取图像 - 提取图像src并使其成为另一个图像的src
- 当源是IE/EDGE上的加密令牌视频时,Canvas未从azure媒体播放器中提取图像
- 如何使用动力学JS从其他图像中提取图像
- 从9GAG中提取图像
- 我需要什么类型的正则表达式来从markdown中提取图像url
- Jquery.backstretch.min.js从数据库或变量中提取图像
- 使用Javascript从HTML代码中提取图像url
- 使用PDFJS从单个PDF页面提取图像
- 如何使用jQuery从字符串中提取图像标签
- 从远程源Javascript中提取图像
- 从网页中提取图像源,其中img标签可能会在使用javascript etcq渲染页面时添加
- Angular或Three.js不会从服务器中提取图像,而是从浏览器缓存中提取图像
- 如何从数组中提取图像并放入列表中
- 如何创建Adobe Air应用程序,从应用程序外的计算机上的文件夹中提取图像
- Regex从xml中提取图像
- 从API中提取图像