2

I'm investigating subj, as there's one site where a part of data is accessible after clicking on a said link.

I've a script like this:

#!/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)

But although it's perfectly rendering the page, the click doesn't happen. I've tried with ya.ru and the same approach worked (but it was a button in that case). I'm out of ideas. Tried setting UA, playing with waits (it's not fast, that page), using js_source, but cannot click a thing, although I see the element is found.

aikipooh
  • 137
  • 1
  • 19
  • 1
    What version of splash are you using? In Splash 2.1 there is `splash:mouse_click` ([example](http://splash.readthedocs.io/en/latest/scripting-ref.html#splash-mouse-click)). Also might be worth reading ([Trigger jquery click](https://stackoverflow.com/questions/1694595/can-i-call-jquery-click-to-follow-an-a-link-if-i-havent-bound-an-event-hand)) – Adelin Dec 21 '17 at 13:43
  • @Adelin I've splash 3.0 from master, and mouse_click works. – aikipooh Dec 22 '17 at 05:44

1 Answers1

1

The a element that you locate with your CSS selector is not clickable - see how its href value is set to link to nothing:

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

You need to click the parent li element instead:

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

Worked for me - got the "Place" bet type selected.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195