日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python使用selenium_如何在python中使用selenium的示例

發布時間:2024/7/23 python 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python使用selenium_如何在python中使用selenium的示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

最近基于selenium寫了一個python小工具,記錄下學習記錄,自己運行的環境是Ubuntu 14.04.4, Python 2.7,Chromium 49.0,ChromeDriver 2.16

selenium簡介

selenium提供了一個通用的接口,可模擬用戶來操作瀏覽器,比如用于自動化測試等.

selenium的核心是WebDriver,它提供了一組接口,這些接口能夠操作各種跨平臺的瀏覽器.各大瀏覽器廠商.

各大瀏覽器廠商也支持Selenium,將其作為瀏覽器的一部分.

selenium工具集提供了WebDriver,Selenium IDE,Selenium-Grid等

Selenium 1.0 + WebDriver = Selenium 2.0

Selenium WebDriver是Selenium Remote Control(Selenium-RC)的繼承者.

WebDriver提供了更簡單和簡潔的接口,克服了Selenium-RC API一些限制.

相比Selenium 1.0,WebDriver是面向對象式的服務.

WebDriver驅動瀏覽器更有效率,提供了比Selenium 1.0更多的功能

Selenium RC只能在單機上運行,WebDriver則提供了遠程操作的功能

selenium基本使用

selenium運行需要什么

主要包括三部分:selenium selenium,瀏覽器driver,瀏覽器selenium selenium是一組通用的接口,而不同的瀏覽器提供其自身的driver(大部分是官方的),瀏覽器則被模擬控制操作的終端.

安裝

簡單的使用

API使用

可參考/usr/local/lib/python2.7/dist-packages/selenium

Chrome WebDriver

selenium.webdriver.chrome.webdriver.WebDriver(executable_path='chromedriver', port=0, chrome_options=None, service_args=None, desired_capabilities=None, service_log_path=None)

ChromeOptions

可以通過ChromeDriver session配置ChromeDriver session ChromeDriverconvenient methods for setting ChromeDriver-specific capabilities

直接使用DesiredCapabilities

ChromeOptions是構建在DesiredCapabilities之上的,為了使用DesiredCapabilities,必須知道capability的Key/value對.

chromedriver運行方式

The ChromeDriver class不斷的創建實例,會浪費很多的時間,可以通過兩個方式解決.

使用ChromeDriverService

開啟單獨的ChromeDriver服務

RemoteWebDriverServer

The RemoteWebDriver is composed of two pieces: a client and a server. The client is your WebDriver test and the server is simply a Java servlet, which can be hosted in any modern JEE app server. The server will always run on the machine with the browser you want to test.

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

原文鏈接:https://www.jianshu.com/p/3f7c40dbc317

總結

以上是生活随笔為你收集整理的python使用selenium_如何在python中使用selenium的示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。