8

通过Python来调用Chrom浏览器,进入设定网页

 3 years ago
source link: https://blog.csdn.net/wly1790775384/article/details/111405145
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

通过Python来调用Chrom浏览器,进入设定网页

前期准备工作:
库:selenium
Chrome驱动:链接
(注意:下载的驱动要和自己电脑上的Chrom版本相同)
将驱动文件放置到两个地方
(1)Chrome浏览器的安装地址

在这里插入图片描述
(2)python的安装地址
在这里插入图片描述
环境变量设置:
设置浏览器的地址非常简单。 我们可以手动创建一个存放浏览器驱动的目录,如: F:\GeckoDriver , 将下载的浏览器驱动文件(例如:chromedriver、geckodriver)丢到该目录下。

我的电脑–>属性–>系统设置–>高级–>环境变量–>系统变量–>Path,将“F:\GeckoDriver”目录添加到Path的值中。比如:Path字段;F:\GeckoDriver

简单的测试程序:
#引入selenium库中的 webdriver 模块
from selenium import webdriver

#打开谷歌浏览器
driver = webdriver.Chrome()
#打开百度搜索主页
driver.get(‘https://i.csdn.net/#/uc/profile’)

第一次写博客基本都是转的别的大佬的:
凯耐


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK