【发布时间】:2015-11-16 09:36:50
【问题描述】:
我在解析href 标签时需要帮助。目前,所有内容都被解析为文本,但是我需要解析链接,以便稍后使用 AJAX 将其发送到 php 页面。
我的 HTML 看起来像:
<div id="word_content">
<br>Testing Time: 2015-10-29 17:57:11<br>
Total Age: 19<br>
Total Friemd: 9<br>
Total Family: 10<br>
<br>
Here are the suggestions - Him_530037_: <a href="www.mytarget.com="_blank">93358546</a>
<h3>Overview</h3><br>
<ul>
<li>(The overlap provided is not good)</li>
</ul>
<h3>Structure</h3><br>
<h4>Target:</h4><br>
<ul>
<li>Audience.</li>
<li>Lookalike</li>
<li>Overlap of Audience</li>
<a href="https://www.myPage.com/lolPagess/?id=06" target="_blank">06<font name="names" hidden="" style="display: inline;"> - Page Likes</font></a>
</ul>
Jquery 代码是这样的:
var headTags = $("div#word_content").find("*").filter(function(){
return /^h/i.test(this.nodeName);
});
var output = {};
$(headTags).each(function(){
var currentHead = $(this);
var nextNextElem = currentHead.next().next();
var innerText = [];
if(nextNextElem.prop("tagName") == "UL")
{
nextNextElem.find("li").each(function(){
innerText.push($(this).text());
});
}
output[currentHead.text()] = innerText;
});
目前,Jquery 正在获取数据,但它只捕获文本而不是链接。我还需要解析链接,以便可以在更多页面中使用此链接。有人可以帮忙吗?
【问题讨论】:
-
这里
nextNextElem.find("li").each(function(){ innerText.push($(this).text()); });你只在寻找li但链接不是li的一部分,所以它被排除在外了。 -
如何添加该链接?你能帮忙吗
标签: javascript php jquery html