diff --git a/README.md b/README.md index 95aa492..48a5ec6 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ [腾讯视频热播列表](腾讯视频热播列表/) -[ QWebView 与 python 通过js交互 特效 - 已失效 未更新](https://github.com/892768447/PhotoEffects) +[ QWebView 与 python 通过js交互 特效 - QWebEngine需要改代码](https://github.com/892768447/PhotoEffects) ### II、功能型 @@ -65,8 +65,10 @@ - 浏览器QWebEngine模块例子 1. - [ 浏览器获取Cookie](浏览器获取Cookie/) 1. - [ 浏览器下载功能](partner_625781186/QWebEngineView下载文件) - 1. - [ 梦幻树 QWebView - 已失效 未更新](梦幻树/) - 1. - [ QWebView 与 python 通过js交互 特效 - 已失效 未更新](https://github.com/892768447/PhotoEffects) + 1. - [ 浏览器开启调试工具](partner_625781186/14.多进程爬虫) + + 1. - [ 梦幻树 QWebView - QWebEngine需要改代码](梦幻树/) + 1. - [ QWebView 与 python 通过js交互 特效 - QWebEngine需要改代码](https://github.com/892768447/PhotoEffects) #### 2.2 框架 diff --git a/partner_625781186/14.多进程爬虫/README.md b/partner_625781186/14.多进程爬虫/README.md new file mode 100644 index 0000000..88117fb --- /dev/null +++ b/partner_625781186/14.多进程爬虫/README.md @@ -0,0 +1,16 @@ +# QWebEngineView 开启控制台 + +需要在 设置环境变量 , 并在浏览器中访问 , 因为访问的是网页 ,并且扩展工具选择页面元素 会加一个 动态高亮的样式类 , 所以可以用这个方法 来获取页面 元素的html相关属性元素。 + +```python +if __name__ == "__main__": + ... + + import os + os.environ["QTWEBENGINE_REMOTE_DEBUGGING"] = "9000" + + ... + +``` + +![1](ScreenShot/1.gif) \ No newline at end of file diff --git a/partner_625781186/14.多进程爬虫/ScreenShot/1.gif b/partner_625781186/14.多进程爬虫/ScreenShot/1.gif new file mode 100644 index 0000000..389328d Binary files /dev/null and b/partner_625781186/14.多进程爬虫/ScreenShot/1.gif differ diff --git a/partner_625781186/14.多进程爬虫/__init__.py b/partner_625781186/14.多进程爬虫/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/partner_625781186/14.多进程爬虫/icons/add_page.png b/partner_625781186/14.多进程爬虫/icons/add_page.png new file mode 100644 index 0000000..ff8f207 Binary files /dev/null and b/partner_625781186/14.多进程爬虫/icons/add_page.png differ diff --git a/partner_625781186/14.多进程爬虫/icons/back.png b/partner_625781186/14.多进程爬虫/icons/back.png new file mode 100644 index 0000000..fc13555 Binary files /dev/null and b/partner_625781186/14.多进程爬虫/icons/back.png differ diff --git a/partner_625781186/14.多进程爬虫/icons/clipboard.png b/partner_625781186/14.多进程爬虫/icons/clipboard.png new file mode 100644 index 0000000..b689cff Binary files /dev/null and b/partner_625781186/14.多进程爬虫/icons/clipboard.png differ diff --git a/partner_625781186/14.多进程爬虫/icons/cross.png b/partner_625781186/14.多进程爬虫/icons/cross.png new file mode 100644 index 0000000..6b9fa6d Binary files /dev/null and b/partner_625781186/14.多进程爬虫/icons/cross.png differ diff --git a/partner_625781186/14.多进程爬虫/icons/lock.png b/partner_625781186/14.多进程爬虫/icons/lock.png new file mode 100644 index 0000000..571c16d Binary files /dev/null and b/partner_625781186/14.多进程爬虫/icons/lock.png differ diff --git a/partner_625781186/14.多进程爬虫/icons/next.png b/partner_625781186/14.多进程爬虫/icons/next.png new file mode 100644 index 0000000..977b9e5 Binary files /dev/null and b/partner_625781186/14.多进程爬虫/icons/next.png differ diff --git a/partner_625781186/14.多进程爬虫/icons/penguin.png b/partner_625781186/14.多进程爬虫/icons/penguin.png new file mode 100644 index 0000000..7e93b80 Binary files /dev/null and b/partner_625781186/14.多进程爬虫/icons/penguin.png differ diff --git a/partner_625781186/14.多进程爬虫/icons/question.png b/partner_625781186/14.多进程爬虫/icons/question.png new file mode 100644 index 0000000..b9ca7cb Binary files /dev/null and b/partner_625781186/14.多进程爬虫/icons/question.png differ diff --git a/partner_625781186/14.多进程爬虫/icons/renew.png b/partner_625781186/14.多进程爬虫/icons/renew.png new file mode 100644 index 0000000..dda7132 Binary files /dev/null and b/partner_625781186/14.多进程爬虫/icons/renew.png differ diff --git a/partner_625781186/14.多进程爬虫/icons/save.png b/partner_625781186/14.多进程爬虫/icons/save.png new file mode 100644 index 0000000..966a19d Binary files /dev/null and b/partner_625781186/14.多进程爬虫/icons/save.png differ diff --git a/partner_625781186/14.多进程爬虫/多进程爬虫.py b/partner_625781186/14.多进程爬虫/多进程爬虫.py new file mode 100644 index 0000000..002d8a8 --- /dev/null +++ b/partner_625781186/14.多进程爬虫/多进程爬虫.py @@ -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_()) +