最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python webdriver.Chrome()的使用解讀

 更新時(shí)間:2023年02月25日 09:20:17   作者:HHT0506  
這篇文章主要介紹了Python webdriver.Chrome()的使用,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

webdriver.Chrome()的使用

1.前提

Python與Chrome路徑下均安裝chromedriver.exe。

2.chromedriver.exe版本選擇及下載

chromedriver.exe版本需要與瀏覽器版本一致:

3.安裝

下載后解壓,將 chromedriver.exe復(fù)制到下面兩個(gè)目錄中:

  • Chrome目錄:比如C:\Program Files (x86)\Google\Chrome\Application
  • Python目錄:比如D:\Softwares\Python39

4.添加環(huán)境變量

將上述Chrome路徑添加進(jìn)系統(tǒng)環(huán)境光變量,Python使用時(shí)應(yīng)該加入環(huán)境變量了,這個(gè)就不用管了。

5.測試代碼

import time
from selenium import webdriver
driver = 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參數(shù)解釋

通過源碼看解釋

最直接最不講道理的方式就是看源碼,使用之前一定要學(xué)會(huì)看說明書。

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

from selenium import webdriver

Broswer = 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并允許您驅(qū)動(dòng)瀏覽器。

你需要從http://chromedriver.storage.googleapis.com/index.html下載ChromeDriver的可執(zhí)行文件。

沒有下ChromeDriver的小伙伴根據(jù)自己瀏覽器版本下載相應(yīng)的ChromeDriver版本,兩者版本關(guān)系ChromeDriver版本>=Chrome版本。

參數(shù)解釋:

  • executable_path - 可執(zhí)行文件的路徑。如果使用默認(rèn)值,則假定可執(zhí)行文件位于$PATH中。
  • port- 你希望服務(wù)運(yùn)行的端口,如果為0,使用空閑端口。
  • options - 這是ChromeOptions的一個(gè)實(shí)例
  • service_args - 要傳遞給驅(qū)動(dòng)程序服務(wù)的args列表
  • desired_capabilities -僅具有非瀏覽器特定功能的字典對象,例如“proxy”或“loggingPref”。
  • service_log_path - 記錄來自驅(qū)動(dòng)程序的信息存放路徑。
  • chrome_options - chrome選項(xiàng)。
  • 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

并且告知此警告被棄用

關(guān)于executable_path解釋:value是ChromeDriver.exe路徑。

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • 解決django框架model中外鍵不落實(shí)到數(shù)據(jù)庫問題

    解決django框架model中外鍵不落實(shí)到數(shù)據(jù)庫問題

    這篇文章主要介紹了解決django框架model中外鍵不落實(shí)到數(shù)據(jù)庫問題,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-05-05
  • Python?matplotlib實(shí)現(xiàn)多子圖布局

    Python?matplotlib實(shí)現(xiàn)多子圖布局

    多子圖布局是指在一個(gè)圖像中同時(shí)顯示多個(gè)子圖,每個(gè)子圖可以是獨(dú)立的圖形或者是相互關(guān)聯(lián)的圖形,下面我們就來了解下matplotlib是如何實(shí)現(xiàn)多子圖布局的吧
    2023-12-12
  • python用pd.read_csv()方法來讀取csv文件的實(shí)現(xiàn)

    python用pd.read_csv()方法來讀取csv文件的實(shí)現(xiàn)

    本文主要介紹了python用pd.read_csv()方法來讀取csv文件的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-06-06
  • YOLOv5以txt或json格式輸出預(yù)測結(jié)果的方法詳解

    YOLOv5以txt或json格式輸出預(yù)測結(jié)果的方法詳解

    這篇文章主要給大家介紹了關(guān)于YOLOv5以txt或json格式輸出預(yù)測結(jié)果的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2023-03-03
  • Django nginx配置實(shí)現(xiàn)過程詳解

    Django nginx配置實(shí)現(xiàn)過程詳解

    這篇文章主要介紹了Django nginx配置實(shí)現(xiàn)過程詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-09-09
  • 基于python實(shí)現(xiàn)智能用例生成工具

    基于python實(shí)現(xiàn)智能用例生成工具

    這篇文章主要為大家詳細(xì)介紹了如何基于python實(shí)現(xiàn)智能用例生成工具,即根據(jù)輸入的功能點(diǎn),生成通用測試點(diǎn),感興趣的小伙伴可以跟隨小編一起了解下
    2023-09-09
  • python多線程socket編程之多客戶端接入

    python多線程socket編程之多客戶端接入

    這篇文章主要為大家詳細(xì)介紹了python多線程socket編程之多客戶端接入,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-09-09
  • Python中Merge使用的示例詳解

    Python中Merge使用的示例詳解

    Python里的merger函數(shù)是數(shù)據(jù)分析工作中最常見的函數(shù)之一,類似于MySQL中的join函數(shù)和Excel中的vlookup函數(shù)。本文將通過一些簡單的實(shí)力和大家聊聊Merge的使用,需要的可以了解一下
    2023-02-02
  • Python實(shí)現(xiàn)繪制多角星實(shí)例

    Python實(shí)現(xiàn)繪制多角星實(shí)例

    這篇文章要給大家分享Python實(shí)現(xiàn)繪制多角星的實(shí)例,在具備一定的Python編程基礎(chǔ)以后,我們可以結(jié)合for循環(huán)進(jìn)行多角星的編寫,只要簡單的幾次循環(huán),即可以極大的解決重復(fù)編寫相同代碼方面的問題,下面小編將以三角星,五角星為例,進(jìn)而引入如何繪制多角星,需要的朋友可以參考一下
    2021-11-11
  • Python中將字典轉(zhuǎn)換為列表的方法

    Python中將字典轉(zhuǎn)換為列表的方法

    這篇文章主要介紹了Python中將字典轉(zhuǎn)換為列表的方法,需要的朋友可以參考下
    2016-09-09

最新評論

鲁山县| 河西区| 海门市| 望谟县| 凤凰县| 四会市| 托克逊县| 英德市| 同江市| 枝江市| 仙游县| 新蔡县| 绥阳县| 高陵县| 阿尔山市| 南康市| 上饶县| 营山县| 武鸣县| 沐川县| 湘潭县| 邵阳市| 梅河口市| 瓦房店市| 克山县| 屏山县| 翼城县| 兴业县| 罗源县| 定州市| 恩施市| 高台县| 从化市| 浪卡子县| 攀枝花市| 达孜县| 定南县| 吉水县| 虞城县| 靖远县| 巫山县|