如何点击<a> wiyh scapy-splash

时间:2016-07-04 01:54:12

标签: javascript jquery scrapy scrapy-splash

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
'''

it never works. but

document.getElementById("showcaptchad").click()

worked well

question:

1.Whether jQuery does not support click() .

2.how can I click the link like

<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&amp;page=2" data-spm-anchor-id="a220o.1000855.0.0">2</a>

they don't contain id='xxx' or name='xxx' .

I can't use 'getElementById()' or 'getElementsByName()'.

what should I do?

I just want to click once

why so hard (╯°口°)╯(┴—┴

===============================================

After 100000000 times

splash:runjs('document.querySelector("#showcaptchad").click()')

this worked

it looks like not jQuery method

=============================================== I was shown how to do this just now

To use getElementById, getElementByName, getElementsByTagName() and some simple

function can almost do everything

jQuery looks like not necessary

2 个答案:

答案 0 :(得分:1)

您可以使用explained执行此操作,也可以选择包含Javascript onclick handler

的元素

&#13;
&#13;
toList
&#13;
$('a[href=#J_Reviews]').click(function(){
  alert('jQuery way')
})

function myFunction(){
  alert('Javascriptway');
}
&#13;
&#13;
&#13;

答案 1 :(得分:0)

或者您可以使用它来收听点击事件

$('a[href=#J_Reviews]').on('click',function(){
  alert("jQuery way too");
});