source: http://stackoverflow.com/questions/13287490/is-there-a-way-to-use-phantomjs-in-python
The easiest way to use PhantomJS in python is via Selenium. The simplest installation method is
- Install NodeJS
- Using Node's package manager install phantomjs:
npm -g install phantomjs
- install selenium (in your virtualenv, if you are using that)
After installation, you may use phantom as simple as:
from selenium import webdriver
driver = webdriver.PhantomJS() # or add to your PATH
driver.set_window_size(1024, 768) # optional
driver.get('https://google.com/')
driver.save_screenshot('screen.png') # save a screenshot to disk
sbtn = driver.find_element_by_css_selector('button.gbqfba')
sbtn.click()
If your system path environment variable isn't set correctly, you'll need to specify the exact path as an argument to
webdriver.PhantomJS()
. Replace this:driver = webdriver.PhantomJS() # or add to your PATH
... with the following:
driver = webdriver.PhantomJS(executable_path='/usr/local/lib/node_modules/phantomjs/lib/phantom/bin/phantomjs')
References:
- http://selenium-python.readthedocs.org/en/latest/api.html
- How do I set a proxy for phantomjs/ghostdriver in python webdriver?
- http://python.dzone.com/articles/python-testing-phantomjs
P.S
references : http://stackoverflow.com/questions/21168141/can-not-install-packages-using-node-package-manager-in-ubuntu/21171188#21171188
http://stackoverflow.com/questions/13046555/wkhtmltopdf-libfontconfig-so-1-cannot-open-shared-object-file
While I was trying to install phantomjs on Ubuntu 13.10, I'd gotten into severl troubles.
references : http://stackoverflow.com/questions/21168141/can-not-install-packages-using-node-package-manager-in-ubuntu/21171188#21171188
http://stackoverflow.com/questions/13046555/wkhtmltopdf-libfontconfig-so-1-cannot-open-shared-object-file
While I was trying to install phantomjs on Ubuntu 13.10, I'd gotten into severl troubles.
In a nutshell, just issue the following command on *nix terminal:
$ sudo apt-get install nodejs npm nodejs-lagacy libfontconfig1 && sudo npm -g install phantomjs
1. nodejs 설치
2. npm 설치
3. nodejs-legacy설치
4. libfontconfig1 설치
댓글
댓글 쓰기