mechanize (python) click on a javascript type link

后端 未结 2 739
逝去的感伤
逝去的感伤 2021-01-21 08:57

is it possible to have mechanize follow an anchor link that is of type javascript?

I am trying to login into a website in python using mechanize and beautifulsoup.

2条回答
  •  执笔经年
    2021-01-21 09:20

    I don't think this is possible with the mechanize module: it doesn't have the ability to interact with JavaScript: its purely Python and HTTP based.

    That said, you may be intested in python-spidermonkey module, which it seems is aimed at letting you do just this kind of thing. According to it's website it's aim is to let you

    "Execute arbitrary JavaScript code from Python. Allows you to reference arbitrary Python objects and functions in the JavaScript VM"

    I've not used it yet but it certainly looks like it would do what you are looking for, although it is still in alpha.

提交回复
热议问题