| 26 | class Window(QTabWidget): |
| 27 | |
| 28 | def __init__(self, *args, **kwargs): |
| 29 | super(Window, self).__init__(*args, **kwargs) |
| 30 | |
| 31 | # 用户1 |
| 32 | self.webView1 = QWebEngineView(self) |
| 33 | profile1 = QWebEngineProfile('storage1', self.webView1) |
| 34 | # 要设置绝对路径,否则会出现部分问题 |
| 35 | # 比如 reCaptcha 不能加载,见 https://github.com/PyQt5/PyQt/issues/125 |
| 36 | profile1.setPersistentStoragePath(os.path.abspath('Tmp/Storage1')) |
| 37 | print(profile1.cookieStore()) |
| 38 | # 如果要清除cookie |
| 39 | # cookieStore = profile1.cookieStore() |
| 40 | # cookieStore.deleteAllCookies() |
| 41 | # cookieStore.deleteSessionCookies() |
| 42 | page1 = QWebEnginePage(profile1, self.webView1) |
| 43 | self.webView1.setPage(page1) |
| 44 | self.addTab(self.webView1, '用户1') |
| 45 | |
| 46 | # 用户2 |
| 47 | self.webView2 = QWebEngineView(self) |
| 48 | profile2 = QWebEngineProfile('storage2', self.webView2) |
| 49 | profile2.setPersistentStoragePath(os.path.abspath('Tmp/Storage2')) |
| 50 | print(profile2.cookieStore()) |
| 51 | page2 = QWebEnginePage(profile2, self.webView2) |
| 52 | self.webView2.setPage(page2) |
| 53 | self.addTab(self.webView2, '用户2') |
| 54 | |
| 55 | self.webView1.load(QUrl('https://v.qq.com')) |
| 56 | self.webView2.load(QUrl('https://v.qq.com')) |
| 57 | |
| 58 | |
| 59 | if __name__ == '__main__': |