Search code examples
javascriptpythonghost.py

Use ghost.py to click a link linking to a javascript


I have a link (http://bank.hangseng.com/1/PA_1_1_P1/ComSvlet_MiniSite_eng_gif?app=eINVCFundDetailsOV&pri_fund_code=U44217) that I am learning to extract the data inside using python, now I have come to ghost.py.

enter image description here

I want to click the I Agree, which is actually not a hyperlink, but a click activating the javascript, and will bring me to the page I need.

I want to use:

page, resources = ghost.evaluate(
    "document.getElementById('link').click();", expect_loading=True)

As suggested by http://jeanphix.me/Ghost.py/, but checking the source found that the link do not have an ID.

Is it possible, and if yes, how can I use ghost.py to extract the page?


Solution

  • That button simply calls the global agree function. So you can do this:

    page, resources = ghost.evaluate("agree()", expect_loading=True)