selenium环境安装并运行

2020-09-08  本文已影响0人  haha_ad25

新购入电脑,需要重新装一遍环境

1.下载anaconda软件包: https://www.anaconda.com/products/individual/get-started

    安装过程中选择将安装目录加入环境变量

    打开cmd,可进入python

2.下载pycharm

    进入File-Settings-Project-Interpreter,加入anaconda的目录

3.conda install 安装其他库,如:selenium

4.安装driver

查看浏览器版本号:chrome://settings/help ,比如:版本 85.0.4183.83(正式版本) (64 位)】

下载对应的driver ,比如:http://chromedriver.storage.googleapis.com/index.html?path=85.0.4183.83/

放到和python.exe相同目录下,并加入环境变量

在cmd中运行chromedriver

5.运行

from seleniumimport webdriver

options= webdriver.ChromeOptions()

options.binary_location= r"D:\Program Files\Google\Chrome\Application\chrome.exe"

browser= webdriver.Chrome(chrome_options=options)

browser.get("https://www.baidu.com/")

注意:脚本名禁止与模块名字相同,如:selenium

           直接运行会显示空白页面,手动设置一下chrome.exe的文件所在地址

上一篇 下一篇

猜你喜欢

热点阅读