问题描述
我想从网络流量中获取一些网址和名称,就像您将在 Chrome 的“网络”选项卡下看到的一样。但是除非您单击某些内容,否则这些内容不会显示。 通过手动使用 chrome,XHR 就在那里,但我也必须手动检查任何 url.... 查了一下,发现用QT比selenium容易
我发现了一些与 QT 相关的内容,但我无法让它循环不同的网页,也无法将文本附加到列表中......我不确定它如何与 QTwidgets 配合使用。
import sys
import time
import re
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebEngineWidgets import *
from PyQt5.QtWebEngineCore import *
from PyQt5.QtCore import QUrl
from PyQt5.QtWebEngineWidgets import QWebEnginePage
urls = ['www.google.com','www.example.com']
test = []
class WebEngineUrlRequestInterceptor(QWebEngineUrlRequestInterceptor):
def __init__(self,parent=None):
super().__init__(parent)
def interceptRequest(self,info):
print(info.requestUrl()) #this is a none type
name = info.requestUrl()
if str(info.requestUrl()).find('.img'): #Find something start with https and end with img
pattern = re.compile('https://[A-z./\d]*?img')
search = re.search(name)
print(search)
test.append(search) #add url into test list
if __name__ == '__main__':
app = QApplication(sys.argv)
view = QWebEngineView()
page = QWebEnginePage()
for i in urls: #load the first webpage,should load the second
page.setUrl(QUrl(i))
t = WebEngineUrlRequestInterceptor()
page.profile().setRequestInterceptor(t)
view.setPage(page)
view.resize(600,400)
view.show()
sys.exit(app.exec_())
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)