iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >Python webdriver.Chrome()如何使用
  • 920
分享到

Python webdriver.Chrome()如何使用

2023-07-05 06:07:49 920人浏览 八月长安

Python 官方文档:入门教程 => 点击学习

摘要

这篇文章主要介绍“python WEBdriver.Chrome()如何使用”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“Python webdriver.Chrome()如何使

这篇文章主要介绍“python WEBdriver.Chrome()如何使用”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“Python webdriver.Chrome()如何使用”文章能帮助大家解决问题。

    webdriver.Chrome()的使用

    1.前提

    Python与Chrome路径下均安装chromedriver.exe

    2.chromedriver.exe版本选择及下载

    • Chrome版本查看:浏览器右上角三个点->帮助->关于Google Chrome

    Python webdriver.Chrome()如何使用

    chromedriver.exe版本需要与浏览器版本一致:

    Python webdriver.Chrome()如何使用

    3.安装

    下载后解压,将 chromedriver.exe复制到下面两个目录中:

    • Chrome目录:比如C:\Program Files (x86)\Google\Chrome\Application

    • Python目录:比如D:\Softwares\python39

    4.添加环境变量

    将上述Chrome路径添加进系统环境光变量,Python使用时应该加入环境变量了,这个就不用管了。

    5.测试代码

    import timefrom selenium import webdriverdriver = webdriver.Chrome()driver.get('https://www.baidu.com/')driver.find_element_by_id("kw").send_keys(u"胡皓天")driver.find_element_by_id("su").click()

    webdriver.Chrome参数解释

    通过源码看解释

    最直接最不讲道理的方式就是看源码,使用之前一定要学会看说明书。

    打算使用jupyter演示的,但是jupyter不支持看源码,所以使用PyCharm吧。

    from selenium import webdriverBroswer = webdriver.Chrome(executable_path="chromedriver", port=0,                 options=None, service_args=None,                 desired_capabilities=None, service_log_path=None,                 chrome_options=None, keep_alive=True)print(webdriver.Chrome.__doc__)""" Controls the ChromeDriver and allows you to drive the browser. You will need to download the ChromeDriver executable from    Http://chromedriver.storage.googleapis.com/index.html"""print(webdriver.Chrome.__init__.__doc__)"""Creates a new instance of the chrome driver.        Starts the service and then creates new instance of chrome driver.        :Args:         - executable_path - path to the executable. If the default is used it assumes the executable is in the $PATH         - port - port you would like the service to run, if left as 0, a free port will be found.         - options - this takes an instance of ChromeOptions         - service_args - List of args to pass to the driver service         - desired_capabilities - Dictionary object with non-browser specific           capabilities only, such as "proxy" or "loggingPref".         - service_log_path - Where to log infORMation from the driver.         - chrome_options - Deprecated argument for options         - keep_alive - Whether to configure ChromeRemoteConnection to use HTTP keep-alive."""

    Chrome Doc解释: 控制ChromeDriver并允许您驱动浏览器。

    你需要从http://chromedriver.storage.googleapis.com/index.html下载ChromeDriver的可执行文件。

    没有下ChromeDriver的小伙伴根据自己浏览器版本下载相应的ChromeDriver版本,两者版本关系ChromeDriver版本>=Chrome版本。

    参数解释:

    • executable_path - 可执行文件的路径。如果使用默认值,则假定可执行文件位于$PATH中。

    • port- 你希望服务运行的端口,如果为0,使用空闲端口。

    • options - 这是ChromeOptions的一个实例

    • service_args - 要传递给驱动程序服务的args列表

    • desired_capabilities -仅具有非浏览器特定功能的字典对象,例如“proxy”或“loggingPref”。

    • service_log_path - 记录来自驱动程序的信息存放路径。

    • chrome_options - chrome选项。

    • keep_alive -是否配置ChromeRemoteConnection使用HTTP keep-alive。

    其中options和chrome_options:使用options代替chrome_options。

     if chrome_options:            warnings.warn('use options instead of chrome_options',                          DeprecationWarning, stacklevel=2)            options = chrome_options

    并且告知此警告被弃用

    关于executable_path解释:value是ChromeDriver.exe路径。

    关于“Python webdriver.Chrome()如何使用”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注编程网Python频道,小编每天都会为大家更新不同的知识点。

    --结束END--

    本文标题: Python webdriver.Chrome()如何使用

    本文链接: https://www.lsjlt.com/news/350022.html(转载时请注明来源链接)

    有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

    本篇文章演示代码以及资料文档资料下载

    下载Word文档到电脑,方便收藏和打印~

    下载Word文档
    猜你喜欢
    • Python webdriver.Chrome()如何使用
      这篇文章主要介绍“Python webdriver.Chrome()如何使用”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“Python webdriver.Chrome()如何使...
      99+
      2023-07-05
    • Python webdriver.Chrome()的使用
      前提 Python与Chrome路径下均安装chromedriver.exe。 2.chromedriver.exe版本选择及下载 下载地址为:http://npm.taobao.org/mirror...
      99+
      2023-10-04
      python chrome 开发语言
    • Python——调用webdriver.Chrome() 报错
      今天运行脚本,报错内容如下:  collecting ... login_case.py:None (login_case.py) login_case.py:11: in     dr = webdriver.Chrome() D:\...
      99+
      2023-10-23
      python chrome 开发语言
    • driver=webdriver.Chrome()报错如何解决
      本篇内容介绍了“driver=webdriver.Chrome()报错如何解决”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!driver =...
      99+
      2023-07-05
    • python httpx如何使用
      什么是 HttpxHttpx 是一个 Python 库,它提供了一个现代化的、易于使用的 HTTP 客户端和服务器。Httpx 可以与 Python 的异步框架协同工作,并支持 WebSocket 和 HTTP/2。Httpx 具有极佳的性...
      99+
      2023-05-14
      Python httpx
    • python如何使用plt.suptitle()
      这篇文章给大家分享的是有关python如何使用plt.suptitle()的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。plt.suptitle()真个图形添加标题:plt.fi...
      99+
      2024-04-02
    • python如何使用plt.tight_layout()
      这篇文章给大家分享的是有关python如何使用plt.tight_layout()的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。plt.tight_layout()在绘制多个图形...
      99+
      2024-04-02
    • python如何使用to_csv
      这篇文章主要为大家展示了“python如何使用to_csv”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“python如何使用to_csv”这篇文章吧。to_cs...
      99+
      2024-04-02
    • python如何使用find_element_by_css_selector()
      这篇文章给大家分享的是有关python如何使用find_element_by_css_selector()的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。find_element_by_css_selec...
      99+
      2023-06-17
    • python如何使用find_element_by_link_text()
      小编给大家分享一下python如何使用find_element_by_link_text(),希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!find_element_by_link_text()1.定位百度页面上"...
      99+
      2023-06-17
    • python如何使用pprint
      这篇文章将为大家详细讲解有关python如何使用pprint,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。pprintPython 的默认print函数完成了它的工作。但是如果尝试使用print函数打印出...
      99+
      2023-06-27
    • python argparse如何使用
      这篇文章主要介绍“python argparse如何使用”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“python argparse如何使用”文章能帮助大家解决问题。一、前言ar...
      99+
      2023-07-05
    • Python如何使用RPC
      本篇内容介绍了“Python如何使用RPC”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!主要内容所谓RPC,是远程过程调用(Remote P...
      99+
      2023-07-02
    • python如何使用plt.subplot()
      这篇文章主要介绍python如何使用plt.subplot(),文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!plt.subplot()另一种可视化多个图形的方法是使用 pl...
      99+
      2024-04-02
    • python如何使用find_element_by_tag_name()
      这篇文章将为大家详细讲解有关python如何使用find_element_by_tag_name(),小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。find_element_by_tag_name()fin...
      99+
      2023-06-17
    • Python urllib如何使用
      本篇内容介绍了“Python urllib如何使用”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!一、简介urllib 库,它是 P...
      99+
      2023-07-04
    • python __add__()如何使用
      这篇文章主要介绍“python __add__()如何使用”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“python __add__()如何使用”文章能帮助大家解决问题。__ad...
      99+
      2023-07-05
    • python如何使用howdoi
      小编给大家分享一下python如何使用howdoi,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!howdoi当你使用terminal终端编程时,通过在遇到问题后会...
      99+
      2023-06-27
    • python如何使用wikipedia
      这篇文章主要介绍python如何使用wikipedia,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!wikipedia维基百科有一个很棒的 API,它允许用户以编程方式访问无与伦比的完全免费的知识和信息。在wikip...
      99+
      2023-06-27
    • python如何使用find_element_by_partial_link_text()
      小编给大家分享一下python如何使用find_element_by_partial_link_text(),相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!find...
      99+
      2023-06-17
    软考高级职称资格查询
    编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
    • 官方手机版

    • 微信公众号

    • 商务合作