我有以下html字符串:
<html>
<head>
</head>
<body>
<table>
<tbody>
<th>
<tr>
<img src=""/>
</tr>
</th>
</tbody>
</table>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
有没有办法只获得img元素?
所以在这种情况下我想要一个像这样的字符串<img src=""/>.
更具体的例子:
$wikiDOM = $("<document>"+ wikiHTML+ "</document>");
var infobox = $wikiDOM.find('.infobox').html();
if(infobox != 'undefined' && infobox !== ""){
var img = infobox.filter( 'img' );
console.log( img[0].outerHTML );
}
Run Code Online (Sandbox Code Playgroud)
其中wikiHTML是我对json格式的wikipedia api的请求,用于几个searchterms.
编辑:
从img和infobox返回:
image:[object Object]
infobox[object Object]
image:[object Object]
infobox[object Object]
image:[object Object]
infobox[object Object]
image:[object Object]
infobox[object Object]
image:[object Object]
infobox[object Object]
image:[object Object]
infobox[object Object]
image:[object …Run Code Online (Sandbox Code Playgroud)