获取所有列表内容并删除链接

时间:2013-09-17 14:31:32

标签: jquery

我已经完成了http://jsfiddle.net/cC8fT/558/,看不出有什么问题

我从维基百科中抓取了<ul><li></li></ul>。我想我至少会尝试使用

列出所有<li>代码的内容
$('ul li').each(function(i) {
    return $(this).text();
});

下面的数据集(它实际上是这个数据集http://en.wikipedia.org/wiki/Reading_and_Leeds_Festivals_line-ups,但我正在尝试一个较小的数据集)

<table class="wikitable plainrowheaders" style="text-align:center;" border="1">
<tr>
<td>Reading Friday</td>
<td>Reading Saturday</td>
<td>Reading Sunday</td>
</tr>
<tr>
<td>Leeds Saturday</td>
<td>Leeds Sunday</td>
<td>Leeds Friday</td>
</tr>
<tr>
<td>
<ul>
<li><a href="/wiki/Green_Day" title="Green Day">Green Day</a></li>
<li><a href="/wiki/System_of_a_Down" title="System of a Down">System of a Down</a></li>
<li><a href="/wiki/Deftones" title="Deftones">Deftones</a></li>
<li><a href="/wiki/Frank_Turner" title="Frank Turner">Frank Turner</a></li>
<li><a href="/wiki/Bring_Me_the_Horizon" title="Bring Me the Horizon">Bring Me the Horizon</a></li>
<li><a href="/wiki/New_Found_Glory" title="New Found Glory">New Found Glory</a></li>
<li><a href="/wiki/Skindred" title="Skindred">Skindred</a></li>
<li><a href="/wiki/While_She_Sleeps" title="While She Sleeps">While She Sleeps</a></li>
</ul>
</td>
<td>
<ul>
<li><a href="/wiki/Eminem" title="Eminem">Eminem</a></li>
<li><a href="/wiki/Chase_%26_Status" title="Chase &amp; Status">Chase &amp; Status</a></li>
<li><a href="/wiki/Foals" title="Foals">Foals</a></li>
<li><a href="/wiki/White_Lies_(band)" title="White Lies (band)">White Lies</a></li>
<li><a href="/wiki/Twin_Atlantic" title="Twin Atlantic">Twin Atlantic</a></li>
<li><a href="/wiki/EarlWolf" title="EarlWolf" class="mw-redirect">EarlWolf</a></li>
<li><a href="/wiki/The_Blackout_(band)" title="The Blackout (band)">The Blackout</a></li>
<li><a href="/wiki/Lower_Than_Atlantis" title="Lower Than Atlantis">Lower Than Atlantis</a></li>
<li><a href="/wiki/Mallory_Knox_(band)" title="Mallory Knox (band)">Mallory Knox</a></li>
</ul>
</td>
<td>
<ul>
<li><a href="/wiki/Biffy_Clyro" title="Biffy Clyro">Biffy Clyro</a></li>
<li><a href="/wiki/Nine_Inch_Nails" title="Nine Inch Nails">Nine Inch Nails</a></li>
<li><a href="/wiki/Fall_Out_Boy" title="Fall Out Boy">Fall Out Boy</a></li>
<li><a href="/wiki/The_Lumineers" title="The Lumineers">The Lumineers</a></li>
<li><a href="/wiki/Editors_(band)" title="Editors (band)">Editors</a></li>
<li><a href="/wiki/Don_Broco" title="Don Broco">Don Broco</a></li>
<li><a href="/wiki/Hadouken!" title="Hadouken!">Hadouken!</a></li>
<li><a href="/wiki/We_Are_the_In_Crowd" title="We Are the In Crowd">We Are the In Crowd</a></li>
<li><a href="/wiki/Bury_Tomorrow" title="Bury Tomorrow">Bury Tomorrow</a></li>
</ul>
</td>
</tr>
</table>

然而,我得到的只是数据集,而不是内容。第二阶段是剥离任何URL,只需抓取文本

1 个答案:

答案 0 :(得分:2)

使用map代替each

var texts = $('ul li').map(function() {
    return $(this).text();
}).get();