url:http(s)://bbs.ngacn.cc/nuke.php?__lib=login&__act=login_ui
<a id="showcaptchad" href="javascript:void(0)" onclick="showCaptchad(this)">xxxxxxxx</a>
script = '''
function main(splash)
splash.images_enabled = false
splash.resource_timeout = 100.0
splash:autoload('http://code.jquery.com/jquery-2.1.3.min.js')
assert(splash:go(splash.args.url))
splash:wait(1)
splash:runjs("$('#showcaptchad').click()")
splash:wait(0.5)
return splash:html()
end
'''
它永远不会起作用。 但是
document.getElementById("showcaptchad").click()
效果很好
问题:
1.jQuery是否不支持click()。
2.如何点击
之类的链接<a tabindex="-1" href="#J_Reviews" rel="nofollow" hidefocus="true" data-index="1">xxxxxxx<em class="J_ReviewsCount" style="display: inline;">62791</em></a>
或
<a href="?spm=a220o.1000855.0.0.JZj6pP&page=2" data-spm-anchor-id="a220o.1000855.0.0">2</a>
它们不包含 id='xxx' 或 name='xxx' 。
我无法使用“getElementById()”或“getElementsByName()”。
我该怎么办?
我只想点击一次
怎么这么难(╯°口°)╯(┴—┴
==================================================
1亿次后
splash:runjs('document.querySelector("#showcaptchad").click()')
这有效
看起来不是 jQuery 方法
================================================== 刚才向我展示了如何执行此操作
使用 getElementById、getElementByName、getElementsByTagName() 和一些简单的
函数几乎可以做所有事情
jQuery 看起来没有必要
最佳答案
您可以使用Javascript onclick handler来做到这一点或者您可以使用 jquery atribute selector 选择元素
$('a[href=#J_Reviews]').click(function(){
alert('jQuery way')
})
function myFunction(){
alert('Javascriptway');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<a tabindex="-1" href="#J_Reviews" rel="nofollow" hidefocus="true" data-index="1">xxxxxxx<em class="J_ReviewsCount" style="display: inline;" >62791</em></a>
or
<a href="?spm=a220o.1000855.0.0.JZj6pP&page=2" data-spm-anchor-id="a220o.1000855.0.0" onclick="myFunction()">2</a>
关于javascript - 如何通过 scapy-splash 单击 <a>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38175972/