想用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。每页有多个结果。
<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。每页有多个结果。
解决方案 »
- js获取光标焦点问题
- 新手求教
- 关于this.constructor的问题
- 关于javascript对象的一个问题( 关于变量的生存周期 )
- window.showModalDialog窗口,用javascript函数,总是给我弹出新窗口
- 怎么用JS读取本地的INI文件,,,并把INI中的内容写入静态HTML页的一些textfield里面?
- 散个关于时间计算代码让大家品评!给分!
- 请问与parent.close()相对的子窗口如何写
- 关于对object 标签如何使用window.open才能弹窗播放的疑问
- 函数赋值时this执行环境的改变原因(后续)
- 怪、怪、怪、牛人们,请帮忙完善代码。
- 显示不全加上滚动条也显示不出来?
{
var obj=document.getElementsByTagName("A")[i];
//其余操作
}
不知道符不符合楼主的要求。
谢谢回答,但是这个页面不止一个<a>。我要找到指定的href,没有class和id,实在不知道怎么操作。
<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
<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>
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");
});
运行后,好像没有得出预想的结果,菜鸟一枚,还请不吝赐教。
这句后面还有别的操作,对href进行操作,这句只是获取到href.