#88 多个用户登录同网站
This commit is contained in:
parent
465d7cf1c7
commit
4cff257d67
6 changed files with 74 additions and 1 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -3,6 +3,9 @@ __pycache__/
|
|||
*.py[co]
|
||||
*$py.class
|
||||
|
||||
Tmp
|
||||
Tmp/*
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
|
|
|
@ -60,6 +60,7 @@ encoding//QTreeWidget/testTreeWidget.py=utf-8
|
|||
encoding//QWebEngineView/GetCookie.py=utf-8
|
||||
encoding//QWebEngineView/JsSignals.py=utf-8
|
||||
encoding//QWebEngineView/ScreenShotPage.py=utf-8
|
||||
encoding//QWebEngineView/SiteDiffUser.py=utf-8
|
||||
encoding//QWebView/DreamTree.py=utf-8
|
||||
encoding//QWebView/GetCookie.py=utf-8
|
||||
encoding//QWebView/JsSignals.py=utf-8
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
- [获取Cookie](#1获取Cookie)
|
||||
- [和Js交互操作](#2和Js交互操作)
|
||||
- [网页整体截图](#3网页整体截图)
|
||||
- [同网站不同用户](#4同网站不同用户)
|
||||
|
||||
## 1、获取Cookie
|
||||
[运行 GetCookie.py](GetCookie.py)
|
||||
|
@ -27,4 +28,11 @@
|
|||
1. 方式1:目前通过不完美方法(先调整`QWebEngineView`的大小为`QWebEnginePage`的内容大小,等待一定时间后截图再还原大小)
|
||||
2. 方式2:通过js库`html2canvas`对指定元素截图,得到`base64`编码的数据并调用接口函数传递到py代码中
|
||||
|
||||
![ScreenShotPage](ScreenShot/ScreenShotPage.gif)
|
||||
![ScreenShotPage](ScreenShot/ScreenShotPage.gif)
|
||||
|
||||
## 4、同网站不同用户
|
||||
[运行 SiteDiffUser.py](SiteDiffUser.py)
|
||||
|
||||
原理是为每个`QWebEngineView`创建一个`QWebEnginePage`,且使用独立的`QWebEngineProfile`,并配置`persistentStoragePath`不同路径
|
||||
|
||||
![SiteDiffUser](ScreenShot/SiteDiffUser.gif)
|
BIN
QWebEngineView/ScreenShot/SiteDiffUser.gif
Normal file
BIN
QWebEngineView/ScreenShot/SiteDiffUser.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 205 KiB |
60
QWebEngineView/SiteDiffUser.py
Normal file
60
QWebEngineView/SiteDiffUser.py
Normal file
|
@ -0,0 +1,60 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Created on 2019年8月23日
|
||||
@author: Irony
|
||||
@site: https://pyqt5.com https://github.com/PyQt5
|
||||
@email: 892768447@qq.com
|
||||
@file: QWebEngineView.SiteDiffUser
|
||||
@description: 同个网站不同用户
|
||||
"""
|
||||
from PyQt5.QtCore import QUrl
|
||||
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage,\
|
||||
QWebEngineProfile
|
||||
from PyQt5.QtWidgets import QTabWidget
|
||||
|
||||
|
||||
__Author__ = 'Irony'
|
||||
__Copyright__ = 'Copyright (c) 2019'
|
||||
__Version__ = 'Version 1.0'
|
||||
|
||||
|
||||
class Window(QTabWidget):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(Window, self).__init__(*args, **kwargs)
|
||||
|
||||
# 用户1
|
||||
self.webView1 = QWebEngineView(self)
|
||||
profile1 = QWebEngineProfile('storage1', self.webView1)
|
||||
profile1.setPersistentStoragePath('Tmp/Storage1')
|
||||
print(profile1.cookieStore())
|
||||
# 如果要清除cookie
|
||||
# cookieStore = profile1.cookieStore()
|
||||
# cookieStore.deleteAllCookies()
|
||||
# cookieStore.deleteSessionCookies()
|
||||
page1 = QWebEnginePage(profile1, self.webView1)
|
||||
self.webView1.setPage(page1)
|
||||
self.addTab(self.webView1, '用户1')
|
||||
|
||||
# 用户2
|
||||
self.webView2 = QWebEngineView(self)
|
||||
profile2 = QWebEngineProfile('storage2', self.webView2)
|
||||
profile2.setPersistentStoragePath('Tmp/Storage2')
|
||||
print(profile2.cookieStore())
|
||||
page2 = QWebEnginePage(profile2, self.webView2)
|
||||
self.webView2.setPage(page2)
|
||||
self.addTab(self.webView2, '用户2')
|
||||
|
||||
self.webView1.load(QUrl('https://v.qq.com'))
|
||||
self.webView2.load(QUrl('https://v.qq.com'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
from PyQt5.QtWidgets import QApplication
|
||||
app = QApplication(sys.argv)
|
||||
w = Window()
|
||||
w.show()
|
||||
sys.exit(app.exec_())
|
|
@ -134,6 +134,7 @@ https://pyqt5.com 社区是专门针对PyQt5学习和提升开设的博客网站
|
|||
- [获取Cookie](QWebEngineView/GetCookie.py)
|
||||
- [和Js交互操作](QWebEngineView/JsSignals.py)
|
||||
- [网页整体截图](QWebEngineView/ScreenShotPage.py)
|
||||
- [同网站不同用户](QWebEngineView/SiteDiffUser.py)
|
||||
- [浏览器下载文件](Test/partner_625781186/6.QWebEngineView下载文件)
|
||||
- [打印网页](Test/partner_625781186/17_打印预览qwebengineview)
|
||||
|
||||
|
|
Loading…
Reference in a new issue