Sometimes, we want to use PhantomJS in Python.
In this article, we’ll look at how to use PhantomJS in Python.
How to use PhantomJS in Python?
To use PhantomJS in Python, we can use the PhantomJS driver.
To use it, we run
npm -g install phantomjs-prebuilt
to install PhantomJS.
Then we use it by writing
from selenium import webdriver
driver = webdriver.PhantomJS()
driver.set_window_size(1024, 768)
driver.get('https://google.com/')
driver.save_screenshot('screen.png')
sbtn = driver.find_element_by_css_selector('button')
sbtn.click()
to create the PhantomJS driver with
driver = webdriver.PhantomJS()
We open the webpage with get.
Then we call save_screenshot to save the screenshot of the webpage.
And we call find_element_by_css_selector to find the element with the CSS given selector.
And we click the element with click.
Conclusion
To use PhantomJS in Python, we can use the PhantomJS driver.