1
1
#!/usr/bin/env python
2
2
# -*- coding: utf-8 -*-
3
-
4
3
"""
5
4
Created on 2019年8月23日
6
5
@author: Irony
10
9
@description: 同个网站不同用户
11
10
"""
12
11
12
+ import os
13
+
13
14
try :
14
15
from PyQt5 .QtCore import QUrl
15
- from PyQt5 .QtWebEngineWidgets import QWebEngineView , QWebEnginePage , \
16
- QWebEngineProfile
16
+ from PyQt5 .QtWebEngineWidgets import ( QWebEnginePage , QWebEngineProfile ,
17
+ QWebEngineView )
17
18
from PyQt5 .QtWidgets import QApplication , QTabWidget
18
19
except ImportError :
19
20
from PySide2 .QtCore import QUrl
20
- from PySide2 .QtWebEngineWidgets import QWebEngineView , QWebEnginePage , \
21
- QWebEngineProfile
21
+ from PySide2 .QtWebEngineWidgets import ( QWebEnginePage , QWebEngineProfile ,
22
+ QWebEngineView )
22
23
from PySide2 .QtWidgets import QApplication , QTabWidget
23
24
24
25
@@ -30,7 +31,9 @@ def __init__(self, *args, **kwargs):
30
31
# 用户1
31
32
self .webView1 = QWebEngineView (self )
32
33
profile1 = QWebEngineProfile ('storage1' , self .webView1 )
33
- profile1 .setPersistentStoragePath ('Tmp/Storage1' )
34
+ # 要设置绝对路径,否则会出现部分问题
35
+ # 比如 reCaptcha 不能加载,见 https://github.com/PyQt5/PyQt/issues/125
36
+ profile1 .setPersistentStoragePath (os .path .abspath ('Tmp/Storage1' ))
34
37
print (profile1 .cookieStore ())
35
38
# 如果要清除cookie
36
39
# cookieStore = profile1.cookieStore()
@@ -43,7 +46,7 @@ def __init__(self, *args, **kwargs):
43
46
# 用户2
44
47
self .webView2 = QWebEngineView (self )
45
48
profile2 = QWebEngineProfile ('storage2' , self .webView2 )
46
- profile2 .setPersistentStoragePath ('Tmp/Storage2' )
49
+ profile2 .setPersistentStoragePath (os . path . abspath ( 'Tmp/Storage2' ) )
47
50
print (profile2 .cookieStore ())
48
51
page2 = QWebEnginePage (profile2 , self .webView2 )
49
52
self .webView2 .setPage (page2 )
0 commit comments