From 46360a383b73e18ced10dfae59aa8ec5b34112e9 Mon Sep 17 00:00:00 2001 From: shikong <919411476@qq.com> Date: Wed, 19 Mar 2025 20:26:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E4=BB=93=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ README.MD | 10 ++++++++ main.py | 53 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 .gitignore create mode 100644 README.MD create mode 100644 main.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ee654e2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,70 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# IDE settings +.idea/ +.vscode/ +*.swp +*.swo + +# Project specific +logs/ +*.log +.DS_Store diff --git a/README.MD b/README.MD new file mode 100644 index 0000000..291f577 --- /dev/null +++ b/README.MD @@ -0,0 +1,10 @@ +### 项目依赖安装 +```shell +pip install -r requirements.txt +``` + +### requirements.txt +```shell +pip install pipreqs +pipreqs ./ --encoding=utf8 +``` \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..e4f1182 --- /dev/null +++ b/main.py @@ -0,0 +1,53 @@ +from DrissionPage import Chromium, ChromiumOptions, SessionPage +from concurrent.futures import ThreadPoolExecutor +import atexit +import json + +options = ChromiumOptions() +# 无头模式 +# options.headless() + +browser = Chromium(options) +tab = browser.latest_tab + + +def console_listener(tab): + # 监听控制台 + tab.console.start() + steps = tab.console.steps() + for log in steps: + # print("[console.log]", log) + print(f"[console.log] {log.text}") + +def network_listener(tab): + # 监听网络 + tab.listen.start(targets="192.168.31.139:8126") + for log in tab.listen.steps(): + try: + # print("[network.log]", log) + print(vars(log)) + # request = json.dumps(log.request) + # print(request) + # response = json.dumps(log.response) + print(f"[network.log] {log.method} {log.url} {'request'} {''}") + except Exception as e: + print(e) + +executor = ThreadPoolExecutor(max_workers=2) +executor.submit(console_listener, tab) +executor.submit(network_listener, tab) + +tab.get(url='http://127.0.0.1:8080/pages/index/shopIndex') +tab.change_mode() + + +items = tab.eles("t:body") +for item in items: + print(item) + +def exit(): + print('exit') + browser.quit() + executor.shutdown() + +atexit.register(exit)