QWebEngine开启 控制台 扩展工具

This commit is contained in:
625781186 2018-09-05 15:50:32 +08:00
parent 3c19dec3f6
commit 9b9b91d0d3
15 changed files with 139 additions and 3 deletions

View file

@ -13,7 +13,7 @@
[腾讯视频热播列表](腾讯视频热播列表/) [腾讯视频热播列表](腾讯视频热播列表/)
[ QWebView 与 python 通过js交互 特效 - 已失效 未更新](https://github.com/892768447/PhotoEffects) [ QWebView 与 python 通过js交互 特效 - QWebEngine需要改代码](https://github.com/892768447/PhotoEffects)
### II、功能型 ### II、功能型
@ -65,8 +65,10 @@
- 浏览器QWebEngine模块例子 - 浏览器QWebEngine模块例子
1. - [ 浏览器获取Cookie](浏览器获取Cookie/) 1. - [ 浏览器获取Cookie](浏览器获取Cookie/)
1. - [ 浏览器下载功能](partner_625781186/QWebEngineView下载文件) 1. - [ 浏览器下载功能](partner_625781186/QWebEngineView下载文件)
1. - [ 梦幻树 QWebView - 已失效 未更新](梦幻树/) 1. - [ 浏览器开启调试工具](partner_625781186/14.多进程爬虫)
1. - [ QWebView 与 python 通过js交互 特效 - 已失效 未更新](https://github.com/892768447/PhotoEffects)
1. - [ 梦幻树 QWebView - QWebEngine需要改代码](梦幻树/)
1. - [ QWebView 与 python 通过js交互 特效 - QWebEngine需要改代码](https://github.com/892768447/PhotoEffects)
#### 2.2 框架 #### 2.2 框架

View file

@ -0,0 +1,16 @@
# QWebEngineView 开启控制台
需要在 设置环境变量 并在浏览器中访问 因为访问的是网页 ,并且扩展工具选择页面元素 会加一个 动态高亮的样式类 所以可以用这个方法 来获取页面 元素的html相关属性元素。
```python
if __name__ == "__main__":
...
import os
os.environ["QTWEBENGINE_REMOTE_DEBUGGING"] = "9000"
...
```
![1](ScreenShot/1.gif)

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 712 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 589 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 533 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 544 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 590 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 582 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 802 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 468 B

View file

@ -0,0 +1,118 @@
import sys
import cgitb
sys.excepthook = cgitb.Hook(1, None, 5, sys.stderr, 'text')
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import QWebEngineView
from multiprocessing import Process, Pool
def runPool( i):
print(i)
t= py_process()
t.run()
class SWebEngineView(QWebEngineView):
'''
浏览器类
'''
def __init__(self, parent=None, url=""):
super(SWebEngineView, self).__init__()
self.parent = parent
self.url = url#初始路径
self.tempurl=""#组成跳转链接的临时路径
self.loadFinished.connect(self.gethtml)
self.show()
self.a=0
def gethtml(self, *a, **b):
self.a+=1
print("times:", self.a,"--" , self.page().url())
def closeEvent(self,e):
self.deleteLater()
def clickLieBiao(self):
print("end")
# title
self.page().runJavaScript('''$("#alarmtitle").text()''',
self.get_title)
# content
self.page().runJavaScript('''$("#alarmcontent").text()''',
self.get_content)
# datetime re.sub
self.page().runJavaScript('''$("div.RecoveryDirectoryNav").text()''',
self.get_datetime)
# img
self.page().runJavaScript('''$("#alarmimg").attr("src")''',
self.get_img)
def get_title(self, balance):
# self._dict["title"] = balance
self.appInList(balance)
def get_content(self, balance):
# self._dict["content"] = balance
self.appInList(balance)
def get_datetime(self, balance):
# balance = re.sub(r"【.+?】", "", balance)
# self._dict["datetime"] = balance
self.appInList(balance)
def get_img(self, balance):
# self._dict["img"] = balance
self.appInList(balance)
def appInList(self,blance):
print(blance)
class py_process(Process):
def __init__(self):
super(py_process, self).__init__()
print("1")
self.url= r'https://siteserver.progressivedirect.com/session/setidredirect/?&product=AU&statecode=DC&type=New&refer=PGRX&URL=https://qad.progressivedirect.com/ApplicationStart.aspx?Page=Create&OfferingID=DC&state=DC&zip=20007&SessionStart=True'
self.app = QApplication(sys.argv)
self.browser = SWebEngineView(self, self.url)
def run(self):
print("run1")
self.browser.setUrl(QUrl(self.url))
print("run2")
self.app.exec_()
if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
#pool只能在if __name__ == "__main__":中使用
# pool = Pool(3)
# for i in range(2):
# pool.apply_async(runPool, (i, ))
# pool.close()
# pool.join()
import os
os.environ["QTWEBENGINE_REMOTE_DEBUGGING"] = "9000"
# url= r'https://siteserver.progressivedirect.com/session/setidredirect/?&product=AU&statecode=DC&type=New&refer=PGRX&URL=https://qad.progressivedirect.com/ApplicationStart.aspx?Page=Create&OfferingID=DC&state=DC&zip=20007&SessionStart=True'
url= r'http://www.progressive.com'
browser = SWebEngineView(url)
print("run1")
browser.setUrl(QUrl(url))
print("run2")
sys.exit(app.exec_())