lds_web
说明
把使用 DrissionPage 操作 web 浏览器的功能封装为类,方便在不同地方使用
代码例子
get_web_page
def get_web_page(self):
# from DrissionPage import ChromiumPage
# from DrissionPage import WebPage, ChromiumOptions, SessionOptions
# http://drissionpage.cn/browser_control/connect_browser
co = ChromiumOptions() # 使用指定 ini 文件 ini_path=r'./config1.ini'
# 设置用户文件夹路径。用户文件夹用于存储当前登陆浏览器的账号在使用浏览器时留下的痕迹,包括设置选项等。
# 一般来说用户文件夹的名称是 User Data。对于默认情况下的 Windows 中的 Chrome 浏览器来说,此文件夹位于 %USERPROFILE%\AppData\Local\Google\Chrome\User Data\,
# 也就是当前系统登陆的用户目录的 AppData 内。实际情况可能有变,实际路径请在浏览器输入 chrome://version/,查阅其中的个人资料路径或者叫用户配置路径。
# 若要使用独立的用户信息,可以将 User Data 目录整个复制到自定的其他位置,然后在代码中使用 set_user_data_path() 方法,参数填入自定义位置路径,这样便可使用独立的用户文件夹信息。
# co.set_user_data_path(path)
# 使用系统用户设置
# co.use_system_user_path() # 使用浏览器默认用户文件夹,浏览器已经打开的时候不能使用
if self.is_auto_port:
co.auto_port()
if self.user_data_path:
co.set_user_data_path(self.user_data_path)
so = SessionOptions() # 使用指定 ini 文件 ini_path=r'./config1.ini'
# 当同时传入ChromiumOptions和SessionOptions时,两者都有的属性以ChromiumOptions为准。如timeout和download_path
page = Chromium(addr_or_opts=co, session_options=so) # 通过配置信息创建
# page = WebPage(chromium_options='http://127.0.0.1:9222', session_or_options=so) # 输入地址访问的时候只能访问本机
# page.quit() # 彻底关闭内置的Session对象和Driver对象,并关闭浏览器(如已打开)
# print('所有标签页id组成的列表', page.tabs)
# 标签管理
# http://drissionpage.cn/browser_control/browser_object
# tab = page.get_tab(1)
# print(tab.rect.window_state) # 获取窗口状态
# print(tab.rect.window_location) # 获取窗口位置
# print(tab.rect.window_size) # 获取窗口大小
# tab.set.window.size(500, 500) # 设置窗口大小
# tab.set.window.location(500, 500) # 设置窗口位置
# tab.set.window.max() # 窗口最大化
# page.get('https://www.baidu.com')
# print(f'{page.title} cookies', page.cookies())
# print(f'{page} headers', so.headers)
return page
run_listen_thread
def run_listen_thread(self, targets=None, is_regex=None, method=None, res_type=True, handle_listen_packet=None):
"""
开始监听进程,并支持传递参数给 start_listen
https://drissionpage.cn/browser_control/listener
此方法用于启动监听器,可以设置获取的目标特征
可选择多个特征,符合条件的数据包将被获取
如果监听未停止时调用此方法,已抓取的队列将被清除
注意:
当 targets 不为 None,is_regex 会自动设为 False
即如要使用正则,每次设置 targets 时需显式指定 is_regex=True
参数:
- targets (str, list, tuple, set): 默认值为 None。要匹配的数据包 URL 特征。可以用列表指定多个,为 True 时获取所有
- is_regex (bool): 默认值为 None。设置的 target 是否为正则表达式,为 None 时保持原来设置
- method (str, list, tuple, set): 默认值为 None。设置监听的请求类型,可指定多个,默认为 ('GET', 'POST'),为 True 时监听所有,为 None 时保持原来设置
- res_type (str, list, tuple, set): 默认值为 True。设置监听的 ResourceType 类型,可指定多个,为 True 时监听所有,为 None 时保持原来设置
- handle_listen_packet 处理从网络流量中捕获的数据包
"""
if self.is_listening:
self.log("listen线程已在运行")
return
# 创建线程并传递参数
self.is_listening = True
self.listen_thread = threading.Thread(target=self.start_listen, args=(targets, is_regex, method, res_type, handle_listen_packet), daemon=True)
self.listen_thread.start()
接口演示
Metadata
Release files for lds-web 2.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lds_web-2.3.0.tar.gz | 47.9 kB | Without provenance | Details for lds_web-2.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lds_web-2.3.0-py3-none-any.whl | Python 3 | none | any | Details for lds_web-2.3.0-py3-none-any.whl |
Total release size: 94.9 kB
Release files / lds_web-2.3.0.tar.gz
| Download URL | lds_web-2.3.0.tar.gz |
|---|---|
| Size | 47.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8e536aa9f5829befbd9319df1034b2184bf59f9d467bc942cbfa6c3fc8b88a00
|
|
BLAKE2b-256 checksum How to use checksums |
0d4e35403cab363b078bfee83429372c7cce7b40474f0743529c43d90928125b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.11.1 readme-renderer/44.0 requests/2.32.3 requests-toolbelt/1.0.0 urllib3/2.2.2 tqdm/4.66.4 importlib-metadata/8.0.0 keyring/25.2.1 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.9
|
Release files / lds_web-2.3.0-py3-none-any.whl
| Download URL | lds_web-2.3.0-py3-none-any.whl |
|---|---|
| Size | 47.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
421d9e8735938d1f9e2c0043a883a399ac4dd5b98296afcdaf5f739a18bf1f89
|
|
BLAKE2b-256 checksum How to use checksums |
ffb93edb04a949439b42677babbe660aa63bfec7fac0e8513b6253e26254e9a1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.11.1 readme-renderer/44.0 requests/2.32.3 requests-toolbelt/1.0.0 urllib3/2.2.2 tqdm/4.66.4 importlib-metadata/8.0.0 keyring/25.2.1 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.9
|
Security for lds-web 2.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.