【问题标题】:Clicking on JS link with splash单击带有启动画面的 JS 链接
【发布时间】:2017-12-18 11:33:30
【问题描述】:

我正在调查 subj,因为有一个站点可以在单击所述链接后访问部分数据。

我有一个这样的脚本:

#!/usr/bin/env python

script="""
splash:go(splash.args.url)
splash:wait(10)

splash:runjs("$('a[data-bet-type=FixedPlace]')[0].click()")
splash:wait(10)

return {
  -- html = splash:html(),
  png = splash:png(),
  -- har = splash:har(),
}
"""

from requests import post
from json import dumps, dump
from base64 import b64decode
from contextlib import suppress

if 1:
    endpoint='http://localhost:8050/run'
    j={
        'lua_source': script,
        'url': 'https://www.odds.com.au/horse-racing/bunbury/race-1',
        'timeout': 90,
        'headers': {
            'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:56.0) Gecko/20100101 Firefox/56.0'
        }
    }

r=post(endpoint, headers={'Content-Type': 'application/json'}, data=dumps(j))
print(r.status_code)
if r.status_code != 200:
    print(r.text)
    exit()
j=r.json()

for _ in ('html', 'har'):          
    with suppress(KeyError), open('1.'+_, 'w') as f: f.write(j[_])
with suppress(KeyError), open('1.png', 'wb') as f: f.write(b64decode(j['png']))

if 'har' in j:
    for entry in j['har']['log']['entries']:
        url=entry['request']['url']
        if url.startswith('https://www.odds.com.au'): print(url)

但是,尽管它完美地呈现了页面,但点击并没有发生。我已经尝试过 ya.ru 并且相同的方法有效(但在这种情况下它是一个按钮)。我没主意了。尝试设置UA,玩等待(它不快,那个页面),使用js_source,但不能点击一个东西,虽然我看到元素找到了。

【问题讨论】:

  • 您使用的是什么版本的启动画面?在 Splash 2.1 中有 splash:mouse_click (example)。也可能值得一读 (Trigger jquery click)
  • @Adelin 我已经从大师那里飞溅了 3.0,并且 mouse_click 有效。

标签: javascript python splash-screen


【解决方案1】:

您使用 CSS 选择器找到的 a 元素不可点击 - 看看它的 href 值如何设置为无链接:

<a href="javascript:void(-1);" data-event-id="665605" data-bet-type="FixedPlace">place</a>

您需要改为单击父 li 元素:

$('.bettype__switcher li:last-child')[0].click()

为我工作 - 选择了“地方”投注类型。

【讨论】:

    猜你喜欢
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 2019-09-15
    • 1970-01-01
    • 1970-01-01
    • 2021-12-10
    • 2017-02-21
    • 2019-02-19
    相关资源
    最近更新 更多