在 JavaScript 中模拟人类点击
我有一个小刮刀,我需要使用 JavaScript 单击锚链接。我尝试了几种方法:jQuery.click()
、document.createEvent('MouseEvents')
等。它们都有效,但并不完全有效。像人类点击一样执行(他们像应该那样打开一个选项卡,但不开始下载)。
锚标记具有此属性:
onclick="if (document.getElementById('ReportViewer_ctl01_ctl05_ctl00').selectedIndex == 0) return false;
if (!ClientToolbarReportViewer_ctl01.HandleClientSideExport()) __doPostBack('ReportViewer$ctl01$ctl05$ctl01','');return false;"
我也尝试在命令行中运行到关键点:
__doPostBack('ReportViewer$ctl01$ctl05$ctl01','')
这也可以工作,但不完全像人类点击。
如果需要,我可以详细说明,但目前我正在寻找我认为应该存在的灵丹妙药。
I have a small scraper where I need to click an anchor link using JavaScript. I've tried a few ways: jQuery.click()
, document.createEvent('MouseEvents')
etc. They all sort of worked, however they don't fully execute like a human click (they open a tab like they should but don't start a download).
The anchor tag has this attribute:
onclick="if (document.getElementById('ReportViewer_ctl01_ctl05_ctl00').selectedIndex == 0) return false;
if (!ClientToolbarReportViewer_ctl01.HandleClientSideExport()) __doPostBack('ReportViewer$ctl01$ctl05$ctl01','');return false;"
I've also tried running to crux of this in the command line :
__doPostBack('ReportViewer$ctl01$ctl05$ctl01','')
this also sort of works but not fully like a human click.
I can go into more detail if required however at the moment I am looking for a magic bullet which I think should exist.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我保存了一个粘贴箱,其中保存了两种编程方法。当谷歌决定剥离窗口对象(以及所有其他对象)的默认功能时,我才感到失望>。>
http://pastebin.com/VMHvjRaR
MDN 文档:
document.createEvent
event.initEvent
event.initMouseEvent
element.dispatchEvent
I keep a pastebin saved of two programmatic ways to do it. It's only ever failed me when google decided to strip the window object (and every other object) of their default functions >.>
http://pastebin.com/VMHvjRaR
MDN documentation:
document.createEvent
event.initEvent
event.initMouseEvent
element.dispatchEvent