使用ghost.py单击链接到javascript的链接

使用ghost.py单击链接到javascript的链接,javascript,python,ghost.py,Javascript,Python,Ghost.py,我有一个链接,我正在学习使用python提取其中的数据,现在我来到ghost.py 我想点击我同意,这实际上不是一个超链接,而是一个激活javascript的点击,将带我到我需要的页面 我想使用: page, resources = ghost.evaluate( "document.getElementById('link').click();", expect_loading=True) 根据的建议,但检查源代码时发现链接没有ID 是否可能,如果可能,我如何使用ghost.py提取

我有一个链接,我正在学习使用python提取其中的数据,现在我来到ghost.py

我想点击我同意,这实际上不是一个超链接,而是一个激活javascript的点击,将带我到我需要的页面

我想使用:

page, resources = ghost.evaluate(
    "document.getElementById('link').click();", expect_loading=True)
根据的建议,但检查源代码时发现链接没有ID

是否可能,如果可能,我如何使用ghost.py提取页面?

您可以将document.querySelector与css选择器一起使用。图像具有alt属性,其值为Agree。所以你可以按照下面的步骤来做

document.querySelector('img[alt=Agree]').click()

该按钮只调用全局同意函数。所以你可以这样做:

page, resources = ghost.evaluate("agree()", expect_loading=True)
我尝试了页面,resources=ghost.evaluatedocument.querySelector'img[alt=Agree]'。单击,但似乎不起作用