Is there a way to use PhantomJS in Python?

后端 未结 8 1299
死守一世寂寞
死守一世寂寞 2020-11-22 08:05

I want to use PhantomJS in Python. I googled this problem but couldn\'t find proper solutions.

I find os.popen() may be a good choice. But I couldn\'t

8条回答
  •  既然无缘
    2020-11-22 08:23

    Now since the GhostDriver comes bundled with the PhantomJS, it has become even more convenient to use it through Selenium.

    I tried the Node installation of PhantomJS, as suggested by Pykler, but in practice I found it to be slower than the standalone installation of PhantomJS. I guess standalone installation didn't provided these features earlier, but as of v1.9, it very much does so.

    1. Install PhantomJS (http://phantomjs.org/download.html) (If you are on Linux, following instructions will help https://stackoverflow.com/a/14267295/382630)
    2. Install Selenium using pip.

    Now you can use like this

    import selenium.webdriver
    driver = selenium.webdriver.PhantomJS()
    driver.get('http://google.com')
    # do some processing
    
    driver.quit()
    

提交回复
热议问题