首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >提取数据

提取数据
EN

Stack Overflow用户
提问于 2013-04-06 03:25:18
回答 1查看 59关注 0票数 0

我想从网站中提取数据,数据结构如下

代码语言:javascript
复制
<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 web应用程序

EN

回答 1

Stack Overflow用户

发布于 2013-04-06 03:38:05

使用下面的示例代码,您可以获得<a>标记之间的文本,在您的示例中为Title

如果您想要每个链接的实际链接,则将其存储在link变量中,在您的示例中为index.php?name=News&file=article&topic=3&sid=1510等。

代码语言:javascript
复制
$('.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变量数组设置为数组,以便在其他函数中使用它们。

代码语言:javascript
复制
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>。在你发布的代码中,你把它颠倒了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15841941

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档