我正在尝试解析HTML,并希望获取所有与
<table>...</table>
相邻的<h3>...</h3>
,但是只能从$('h3 + table', thecontents)
中获取第一个<h3></h3><table></table>
。另外,如果我们想根据其内容获取h3
(例如:星期五,12月14日,星期六,12月15日等),该怎么办?$( document ).ready(function() {
$.getJSON('http://www.whateverorigin.org/get?url=' + encodeURIComponent('...') + '&callback=?', function(data){
var thecontents = data.contents;
var required = $('h3 + table', thecontents).html();
$("#hello").html("<pre>" + required + "</pre>");
});
});
thecontents
或data.contents
的内容是:
<html>
...
<h3><strong>Friday, Dec. 14</strong></h3>
<table>...</table>
...
<h3>...</h3>
<table>...</table>
</html>
我的当前网站返回required
或者$('h3 + table',thecontents).html()
<html>
<body id="hello">
<pre>
<p></p>
...
<p></p>
</pre>
</body>
</html>
h3
(或标题)吗? - Shidersz