sey*_*ood 12 python ssl https pyqt pyqt5
我正在使用PyQt5来抓取网页,这对于http:// URL非常有用,但对于https:// URL则完全没有.
我脚本的相关部分如下:
class WebPage(QWebPage):
def __init__(self):
super(WebPage, self).__init__()
self.timerScreen = QTimer()
self.timerScreen.setInterval(2000)
self.timerScreen.setSingleShot(True)
self.timerScreen.timeout.connect(self.handleLoadFinished)
self.loadFinished.connect(self.timerScreen.start)
def start(self, urls):
self._urls = iter(urls)
self.fetchNext()
def fetchNext(self):
try:
url = next(self._urls)
except StopIteration:
return False
else:
self.mainFrame().load(QUrl(url))
return True
def processCurrentPage(self):
url = self.mainFrame().url().toString()
html = self.mainFrame().toHtml()
#Do stuff with html
print('loaded: [%d bytes] %s' % (self.bytesReceived(), url))
def handleLoadFinished(self):
self.processCurrentPage()
if not self.fetchNext():
qApp.quit()
Run Code Online (Sandbox Code Playgroud)
对于安全页面,脚本返回空白页面.回来的唯一html就是<html><head></head><body></body></html>.
我有点失落.我是否缺少与处理安全URL相关的设置?
小智 0
使用PyQt4进行测试并使用HTTPS正常打开页面
import sys
from PyQt4.QtGui import QApplication
from PyQt4.QtCore import QUrl
from PyQt4.QtWebKit import QWebView
class Browser(QWebView):
def __init__(self):
QWebView.__init__(self)
self.loadFinished.connect(self._result_available)
def _result_available(self, ok):
frame = self.page().mainFrame()
print(frame.toHtml())
if __name__ == '__main__':
app = QApplication(sys.argv)
view = Browser()
view.load(QUrl('https://www.google.com'))
app.exec_()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
434 次 |
| 最近记录: |