2013-04-05 186 views
0

我想从一个网站提取数据,这样提取数据

<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> , &nbsp;&nbsp;&nbsp;&nbsp;<strong> 
        <a href="index.php?name=News&file=article&topic=3&sid=1508" class="nav-white">Title </a></strong> , &nbsp;&nbsp;&nbsp;&nbsp;<strong> 
        <a href="index.php?name=News&file=article&topic=3&sid=1502" class="nav-white">Title</a></strong> , &nbsp;&nbsp;&nbsp;&nbsp;<strong> 
        <a href="index.php?name=News&file=article&topic=3&sid=1501" class="nav-white">Title</a></strong> , &nbsp;&nbsp;&nbsp;&nbsp;<strong> 
        <a href="index.php?name=News&file=article&topic=3&sid=1497" class="nav-white">Title</a></strong> , &nbsp;&nbsp;&nbsp;&nbsp;</marquee></span></td> 

我的问题的数据结构是我能得到<a></a>标签之间的链接标题将它们放在一个列表来构建一个Android网络应用

回答

0

随着示例代码下面你可以得到<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); 
}); 

可以使txtlink变量,数组,所以你可以,如果你想在另一个函数中使用它们。

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>一些文字</strong>。在您发布的代码中,您已将其颠倒过来。