1

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?

lokheart
  • 23,743
  • 39
  • 98
  • 169

2 Answers2

0

You can use document.querySelector with css selector. The image has an alt attribute with Agree as its value. So you can do it as follow.

document.querySelector('img[alt=Agree]').click()
falsetru
  • 357,413
  • 63
  • 732
  • 636
  • I tried `page,resources = ghost.evaluate("document.querySelector('img[alt=Agree]').click()")`, but seems not working – lokheart Aug 18 '14 at 22:28
0

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

page, resources = ghost.evaluate("agree()", expect_loading=True)
tcooc
  • 20,629
  • 3
  • 39
  • 57