拦截post数据
This commit is contained in:
parent
9d641744b1
commit
1dfc61ddbb
3 changed files with 11 additions and 3 deletions
|
@ -5,7 +5,7 @@
|
||||||
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="jdk" jdkName="Python 3.5 (venv) (6)" jdkType="Python SDK" />
|
<orderEntry type="jdk" jdkName="Python 3.5" jdkType="Python SDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
<component name="TestRunnerService">
|
<component name="TestRunnerService">
|
||||||
|
|
|
@ -56,5 +56,5 @@
|
||||||
</profile-state>
|
</profile-state>
|
||||||
</entry>
|
</entry>
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.5 (venv) (6)" project-jdk-type="Python SDK" />
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.5" project-jdk-type="Python SDK" />
|
||||||
</project>
|
</project>
|
|
@ -9,7 +9,7 @@ Created on 2019年9月24日
|
||||||
@file: QWebView.BlockAds
|
@file: QWebView.BlockAds
|
||||||
@description: 拦截请求
|
@description: 拦截请求
|
||||||
"""
|
"""
|
||||||
from PyQt5.QtCore import QUrl
|
from PyQt5.QtCore import QUrl, QBuffer, QByteArray
|
||||||
from PyQt5.QtNetwork import QNetworkAccessManager
|
from PyQt5.QtNetwork import QNetworkAccessManager
|
||||||
from PyQt5.QtWebKitWidgets import QWebView
|
from PyQt5.QtWebKitWidgets import QWebView
|
||||||
|
|
||||||
|
@ -32,6 +32,14 @@ class RequestInterceptor(QNetworkAccessManager):
|
||||||
# 拦截百度联盟的广告
|
# 拦截百度联盟的广告
|
||||||
print('block:', url)
|
print('block:', url)
|
||||||
originalReq.setUrl(QUrl())
|
originalReq.setUrl(QUrl())
|
||||||
|
if op == self.PostOperation and outgoingData:
|
||||||
|
# 拦截或者修改post数据
|
||||||
|
# 读取后要重新设置,不然网站接收不到请求
|
||||||
|
data = outgoingData.readAll().data()
|
||||||
|
print('post data:', data)
|
||||||
|
# 修改data后重新设置
|
||||||
|
outgoingData = QBuffer(self)
|
||||||
|
outgoingData.setData(data)
|
||||||
|
|
||||||
return super(RequestInterceptor, self).createRequest(op, originalReq, outgoingData)
|
return super(RequestInterceptor, self).createRequest(op, originalReq, outgoingData)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue