我想从网站中提取数据,数据结构如下
<td class="text-anouncments"><span class="nav-white"><marquee onmouseover=this.stop() onmouseout=this.start() behavior="scroll" width="100%" direction="left" scrollamount="3" scrolldelay="3" ><strong>
<a href="index.php?name=News&file=article&topic=3&sid=1510" class="nav-white">Title</a></strong> , <strong>
<a href="index.php?name=News&file=article&topic=3&sid=1508" class="nav-white">Title </a></strong> , <strong>
<a href="index.php?name=News&file=article&topic=3&sid=1502" class="nav-white">Title</a></strong> , <strong>
<a href="index.php?name=News&file=article&topic=3&sid=1501" class="nav-white">Title</a></strong> , <strong>
<a href="index.php?name=News&file=article&topic=3&sid=1497" class="nav-white">Title</a></strong> , </marquee></span></td>我的问题是,我能否获得<a></a>标签之间的链接标题,将它们放在一个列表中,以构建一个android web应用程序
发布于 2013-04-06 03:38:05
使用下面的示例代码,您可以获得<a>标记之间的文本,在您的示例中为Title
如果您想要每个链接的实际链接,则将其存储在link变量中,在您的示例中为index.php?name=News&file=article&topic=3&sid=1510等。
$('.nav-white').each(function() {
var txt = $(this).text(); //the text between the <a> tags
var link = $(this).attr('href'); //the link that each one points to
//print them to the console just to see that it actually works
console.log(txt);
console.log(link );
});如果愿意,可以将txt和link变量数组设置为数组,以便在其他函数中使用它们。
var texts = new Array();
var links = new Array();
$('.nav-white').each(function() {
texts.push( $(this).text() ); //the text between the <a> tags
links.push( $(this).attr('href') ); //the link that each one points to
});此外,您还键入了错误的strong属性。这是一些文本</strong>。在你发布的代码中,你把它颠倒了。
https://stackoverflow.com/questions/15841941
复制相似问题