想用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。每页有多个结果。

解决方案 »

  1.   

    for(var i=0;i<document.getElementsByTagName("A").length;i++)
    {
    var obj=document.getElementsByTagName("A")[i];
    //其余操作
    }
    不知道符不符合楼主的要求。
      

  2.   


    谢谢回答,但是这个页面不止一个<a>。我要找到指定的href,没有class和id,实在不知道怎么操作。
      

  3.   

    <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>
    <script>
    var href=$("h3.t ~ a").attr("href");
    //其余操作
    </script>
    </body>
    </html>
    如果只有一个class为t的h3,可以用jquery按这个代码获取href
      

  4.   

    刚才又看了下百度搜索的源代码,应该可以这样遍历取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>
      

  5.   

    不太明白楼主的意思如果是找到指定href的a,那么可以遍历a 判断href
      

  6.   

    菜鸟一个,只会根据id或者class寻找指定的href,它的a没有这两个东西。所以
      

  7.   

    刚才我在百度搜索结果页面,用firebug按你说的方法运行,好像没有得出预期的结果。是不是我的操作有问题?我在firebug的console输入:
    var s=document.createElement('script');  
    s.setAttribute('src', 'http://code.jquery.com/jquery-1.7.2.min.js');  
    document.body.appendChild(s); 
    Run,然后继续输入:
    $("h3.t ~ a").each(function()
    {
    var href=$(this).attr("href");
    });  
    运行后,好像没有得出预想的结果,菜鸟一枚,还请不吝赐教。
      

  8.   

    var href=$(this).attr("href");
    这句后面还有别的操作,对href进行操作,这句只是获取到href.