mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
1.5.3
This commit is contained in:
parent
2292888ead
commit
1ecff10583
35
README.en.md
35
README.en.md
@ -364,11 +364,14 @@ Drission objects are used to manage driver and session objects. When multiple pa
|
|||||||
The configuration information of the ini file can be directly read and created, or the configuration information can be passed in during initialization.
|
The configuration information of the ini file can be directly read and created, or the configuration information can be passed in during initialization.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
# Created from the default ini file
|
# Create from the default ini file
|
||||||
drission = Drission()
|
drission = Drission()
|
||||||
|
|
||||||
# Created by other ini files
|
# Create by other ini files
|
||||||
drission = Drission(ini_path ='D:\\settings.ini')
|
drission = Drission(ini_path ='D:\\settings.ini')
|
||||||
|
|
||||||
|
# Create without ini files
|
||||||
|
drission = Drission(read_file = False)
|
||||||
```
|
```
|
||||||
|
|
||||||
To manually pass in the configuration:
|
To manually pass in the configuration:
|
||||||
@ -377,12 +380,18 @@ To manually pass in the configuration:
|
|||||||
# Create with the incoming configuration information (ignore the ini file)
|
# Create with the incoming configuration information (ignore the ini file)
|
||||||
from DrissionPage.config import DriverOptions
|
from DrissionPage.config import DriverOptions
|
||||||
|
|
||||||
driver_options = DriverOptions() # Create driver configuration object
|
# Create a driver configuration object, read_file = False means not to read the ini file
|
||||||
driver_options.binary_location ='D:\\chrome\\chrome.exe' # chrome.exe path
|
do = DriverOptions(read_file = False)
|
||||||
session_options = {'headers': {'User- Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6)'}}
|
|
||||||
driver_path ='D:\\chrome\\chromedriver.exe' # driver_path path
|
|
||||||
|
|
||||||
drission = Drission(driver_options, session_options, driver_path) # incoming configuration
|
# Set the path, if it has been set in the system variable, it can be ignored
|
||||||
|
do.set_paths(chrome_path ='D:\\chrome\\chrome.exe',
|
||||||
|
driver_path ='D:\\chrome\\chromedriver.exe')
|
||||||
|
|
||||||
|
# Settings for s mode
|
||||||
|
session_options = {'headers': {'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6)'}}
|
||||||
|
|
||||||
|
# Incoming configuration, driver_options and session_options are optional, you need to use the corresponding mode to pass in
|
||||||
|
drission = Drission(driver_options, session_options)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@ -505,7 +514,13 @@ You can use these two functions under the page object or element object to find
|
|||||||
|
|
||||||
page.eles() and element.eles() search and return a list of all elements that meet the conditions.
|
page.eles() and element.eles() search and return a list of all elements that meet the conditions.
|
||||||
|
|
||||||
Note: The default element search timeout is 10 seconds, you can also set it as needed.
|
Description:
|
||||||
|
|
||||||
|
- The element search timeout is 10 seconds by default, you can also set it as needed.
|
||||||
|
|
||||||
|
- In the following search statement, the colon: indicates a fuzzy match, and the equal sign = indicates an exact match
|
||||||
|
|
||||||
|
- There are five types of query strings: @attribute name, tag, text, xpath, and css
|
||||||
|
|
||||||
```python
|
```python
|
||||||
# Find by attribute
|
# Find by attribute
|
||||||
@ -557,8 +572,8 @@ ele1 = element.shadow_root.ele('tag:div')
|
|||||||
page.ele('@id:ele_id').ele('tag:div').next.ele('some text').eles('tag:a')
|
page.ele('@id:ele_id').ele('tag:div').next.ele('some text').eles('tag:a')
|
||||||
|
|
||||||
# Simplified writing
|
# Simplified writing
|
||||||
ele1 = page('@id:ele_id')('@class:class_name')
|
eles = page('@id:ele_id')('tag:div').next('some text').eles('tag:a')
|
||||||
ele2 = ele1('tag:li')
|
ele2 = ele1('tag:li').next('some text')
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
@ -288,7 +288,7 @@ page.download(url, save_path)
|
|||||||
pip install DrissionPage
|
pip install DrissionPage
|
||||||
```
|
```
|
||||||
只支持python3.6及以上版本,driver模式目前只支持chrome。
|
只支持python3.6及以上版本,driver模式目前只支持chrome。
|
||||||
若要使用driver模式,须下载chrome和 **对应版本** 的chromedriver。[[chromedriver下载]](https://chromedriver.chromium.org/downloads)
|
若要使用driver模式,须下载chrome和 **对应版本** 的chromedriver。[[chromedriver下载]](http://npm.taobao.org/mirrors/chromedriver)
|
||||||
目前只在Windows环境下作了测试。
|
目前只在Windows环境下作了测试。
|
||||||
|
|
||||||
# 使用方法
|
# 使用方法
|
||||||
@ -314,7 +314,7 @@ from DrissionPage import *
|
|||||||
- 使用时手动传入路径。
|
- 使用时手动传入路径。
|
||||||
- 将路径写入本库的ini文件(推荐)。
|
- 将路径写入本库的ini文件(推荐)。
|
||||||
|
|
||||||
若你选择第三种方式,请在第一次使用本库前,运行这几行代码,把这两个路径记录到ini文件中。
|
若你选择第三种方式,请在第一次使用本库前,运行这几行代码,把这两个路径记录到 ini 文件中,以后程序会自动安装 ini 文件中的配置运行。
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from DrissionPage.easy_set import set_paths
|
from DrissionPage.easy_set import set_paths
|
||||||
@ -369,6 +369,9 @@ drission = Drission()
|
|||||||
|
|
||||||
# 由其它ini文件创建
|
# 由其它ini文件创建
|
||||||
drission = Drission(ini_path = 'D:\\settings.ini')
|
drission = Drission(ini_path = 'D:\\settings.ini')
|
||||||
|
|
||||||
|
# 不从ini文件创建
|
||||||
|
drission = Drission(read_file = False)
|
||||||
```
|
```
|
||||||
|
|
||||||
若要手动传入配置:
|
若要手动传入配置:
|
||||||
@ -377,12 +380,18 @@ drission = Drission(ini_path = 'D:\\settings.ini')
|
|||||||
# 用传入的配置信息创建(忽略ini文件)
|
# 用传入的配置信息创建(忽略ini文件)
|
||||||
from DrissionPage.config import DriverOptions
|
from DrissionPage.config import DriverOptions
|
||||||
|
|
||||||
driver_options = DriverOptions() # 创建driver配置对象
|
# 创建driver配置对象,read_file = False表示不读取ini文件
|
||||||
driver_options.binary_location = 'D:\\chrome\\chrome.exe' # chrome.exe路径
|
do = DriverOptions(read_file = False)
|
||||||
session_options = {'headers': {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6)'}}
|
|
||||||
driver_path = 'D:\\chrome\\chromedriver.exe' # driver_path路径
|
|
||||||
|
|
||||||
drission = Drission(driver_options, session_options, driver_path) # 传入配置
|
# 设置路径,若已在系统变量设置,可忽略
|
||||||
|
do.set_paths(chrome_path = 'D:\\chrome\\chrome.exe',
|
||||||
|
driver_path = 'D:\\chrome\\chromedriver.exe')
|
||||||
|
|
||||||
|
# 用于 s 模式的设置
|
||||||
|
session_options = {'headers': {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6)'}}
|
||||||
|
|
||||||
|
# 传入配置,driver_options 和 session_options都是可选的,须要使用对应模式才须要传入
|
||||||
|
drission = Drission(driver_options, session_options)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@ -408,7 +417,7 @@ page = MixPage(drission)
|
|||||||
page = MixPage(drission, mode='s', timeout=5) # session模式,等待时间5秒(默认10秒)
|
page = MixPage(drission, mode='s', timeout=5) # session模式,等待时间5秒(默认10秒)
|
||||||
|
|
||||||
# 以传入配置信息创建
|
# 以传入配置信息创建
|
||||||
page = MixPage(driver_options=DriverOption, session_options=SessionOption) # 默认 d 模式
|
page = MixPage(driver_options=do, session_options=so) # 默认 d 模式
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@ -505,10 +514,14 @@ ele()返回第一个符合条件的元素,eles()返回所有符合条件的元
|
|||||||
|
|
||||||
page.eles() 和 element.eles() 查找返回符合条件的所有元素列表。
|
page.eles() 和 element.eles() 查找返回符合条件的所有元素列表。
|
||||||
|
|
||||||
注:元素查找超时默认为10秒,你也可以按需要设置。
|
说明:
|
||||||
|
|
||||||
|
- 元素查找超时默认为10秒,你也可以按需要设置。
|
||||||
|
- 下面的查找语句中,冒号 : 表示模糊匹配,等号 = 表示精确匹配
|
||||||
|
- 查询字符串有 @属性名、tag、text、xpath、css五种
|
||||||
|
|
||||||
```python
|
```python
|
||||||
# 根据属性查找
|
# 根据属性查找,@后面可跟任意属性
|
||||||
page.ele('@id:ele_id', timeout = 2) # 查找id为ele_id的元素,设置等待时间2秒
|
page.ele('@id:ele_id', timeout = 2) # 查找id为ele_id的元素,设置等待时间2秒
|
||||||
page.eles('@class') # 查找所有拥有class属性的元素
|
page.eles('@class') # 查找所有拥有class属性的元素
|
||||||
page.eles('@class:class_name') # 查找所有class含有ele_class的元素
|
page.eles('@class:class_name') # 查找所有class含有ele_class的元素
|
||||||
@ -557,8 +570,8 @@ ele1 = element.shadow_root.ele('tag:div')
|
|||||||
page.ele('@id:ele_id').ele('tag:div').next.ele('some text').eles('tag:a')
|
page.ele('@id:ele_id').ele('tag:div').next.ele('some text').eles('tag:a')
|
||||||
|
|
||||||
# 简化写法
|
# 简化写法
|
||||||
ele1 = page('@id:ele_id')('@class:class_name')
|
eles = page('@id:ele_id')('tag:div').next('some text').eles('tag:a')
|
||||||
ele2 = ele1('tag:li')
|
ele2 = ele1('tag:li').next('some text')
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user