V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
jettzhang
V2EX  ›  Python

Python 如何在 GUI 中内嵌一个 chromium 浏览器

  •  
  •   jettzhang · 15 天前 · 1916 次点击

    用什么实现把 chromium 内嵌在 GUI 中,在 GUI 中点击各种功能按钮执行浏览器自动化操作

    9 条回复    2024-04-15 17:28:20 +08:00
    jianchang512
        1
    jianchang512  
       15 天前
    PySide6 QtWebEngineWidgets
    mumbler
        2
    mumbler  
       15 天前
    你不如说一下你想达到的目的,也许有更好的方案,不一定非要 python 去实现,GUI 不是 python 擅长的
    bianhui
        3
    bianhui  
       14 天前
    chromedriver
    l1xnan
        4
    l1xnan  
       14 天前
    搞过类似的,用 Electron 实现吧,js 也很简单
    jones2000
        5
    jones2000  
       14 天前
    CEF
    snitfk
        6
    snitfk  
       14 天前
    这是要做 UI 自动化测试?
    NessajCN
        7
    NessajCN  
       14 天前
    一眼 xy problem
    请直接说原始需求
    hazardous
        8
    hazardous  
       14 天前
    你看看你用的 GUI 框架有没有 webview ,比如 pyqt 就有。
    obird
        9
    obird  
       14 天前
    在 Python 中,你可以使用 PyQt5 与 PyQtWebEngine 库,为你的 GUI 应用程序嵌入 Chromium 浏览器。PyQtWebEngine 是 PyQt 的一部分,它将 Chromium 封装成了一个 Python 文件。
    首先,你需要安装这两个库。你可以使用 pip 命令进行安装:

    pip install PyQt5
    pip install PyQtWebEngine

    然后你可以使用下面的代码创建一个 GUI 窗口并在其中嵌入一个 Chromium 浏览器:

    ···
    from PyQt5.QtCore import QUrl
    from PyQt5.QtWebEngineWidgets import QWebEngineView
    from PyQt5.QtWidgets import QApplication

    class MainWindow(QWebEngineView):
    def __init__(self):
    super(MainWindow, self).__init__()
    self.load(QUrl("https://www.baidu.com"))

    app = QApplication([])
    window = MainWindow()
    window.showMaximized()
    app.exec_()
    ···

    运行后以上的代码会打开一个显示 baidu 主页的浏览器窗口。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1093 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 18:41 · PVG 02:41 · LAX 11:41 · JFK 14:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.