1、安装 selenium
PS C:\WINDOWS\system32> pip install selenium
Collecting selenium
Downloading https://files.pythonhosted.org/packages/80/d6/4294f0b4bce4de0abf13e17190289f9d0613b0a44e5dd6a7f5ca98459853/selenium-3.141.0-py2.py3-none-any.whl (904kB)
100% |████████████████████████████████| 911kB 348kB/s
Requirement already satisfied: urllib3 in c:\program files\python37\lib\site-packages (from selenium) (1.24.1)
Installing collected packages: selenium
Successfully installed selenium-3.141.0
2、下载phantomjs
3、安装(解压)
4、配置环境变量
- C:\Program Files\phantomjs\bin
5、测试
from selenium import webdriver
print("start....\n")
driver = webdriver.PhantomJS(executable_path=r"C:\Program Files\phantomjs\bin\phantomjs.exe")
#phantomjs安装的位置
url='https://www.baidu.com/'
driver.get(url)
driver.save_screenshot("baidu.png")
print("ok!\n")