日期:2014-05-16  浏览次数:20304 次

如何用js获取各个百度搜索结果的链接?无id无class。
想用js获取百度搜索结果的链接。但是不知道怎么操作。
<h3 class="t">
<a onmousedown="return c({'fm': 'albk', 'title': this.innerHTML, 'url': this.href, 'p1': al_c(this)});" href="http://baike.baidu.com/view/18966.htm" target="_blank">
</a>
这个<a>无id,无class。每页有多个结果。

------解决方案--------------------
刚才又看了下百度搜索的源代码,应该可以这样遍历取href:
<html>
<head>
<script src='http://code.jquery.com/jquery-1.7.2.min.js'></script>
<style>
.t
{
}
</style>
</head>
<body>
<h3 class="t"></h3>
<a onmousedown="return c({'fm': 'albk', 'title': this.innerHTML, 'url': this.href, 'p1': al_c(this)});" href="http://baike.baidu.com/view/18966.htm" target="_blank" >
</a>
<h3 class="t"></h3>
<a onmousedown="return c({'fm': 'albk', 'title': this.innerHTML, 'url': this.href, 'p1': al_c(this)});" href="http://baike.baidu.com/view/18967.htm" target="_blank" >
</a>
<script>
$("h3.t ~ a").each(function()
{
var href=$(this).attr("href");
//其余操作
}); 
</script>
</body>
</html>
------解决方案--------------------
不太明白楼主的意思

如果是找到指定href的a,那么可以遍历a 判断href