为什么 python 的 QtWebkit 不能加载大多数网页?

Why does QtWebkit for python not load most web pages?

我正在尝试使用 Pyside 呈现网页的 JavaScript 生成 HTML,然后使用该 html 进行网络抓取。我开始使用 this quick example,但结果非常不一致。

问题是有些页面工作得很好,但其他页面会无限挂起。我并不是说几秒钟后就放弃,我已经让我的脚本 运行 在不同的时间持续了几个小时,但没有取得任何进展。

我目前的代码如下:

import sys
from PySide.QtCore import *
from PySide.QtGui import *
from PySide.QtWebKit import *

class Render(QWebPage):
    def __init__(self, url):
        self.app = QApplication(sys.argv)
        QWebPage.__init__(self)
        self.loadFinished[bool].connect(self.end)
        self.mainFrame().load(url)

        self.app.exec_()

    def end(self, result):
        print 'end'
        self.finalFrame = self.mainFrame()
        self.app.quit()

r = Render('http://pyside.github.io/docs/pyside/PySide/QtWebKit/index.html')
print r.finalFrame.toHtml().encode('ascii', 'ignore')
print 'done'

此页面有效,this answer, but most others ('https://www.google.ca/', 'https://webscraping.com') 中给出的页面无效。

如何加载这些页面?

问题似乎与 SSL 有关。我仍然不确定到底是什么问题,但已通过以下方式解决:

  1. 正在卸载 PySide 的 Anaconda 版本 (1.2.1) 并使用 pip (1.2.4) 安装它。似乎 Anaconda 构建从根本上被破坏了,因为 类 的各种属性在它们应该存在的时候不存在,并且存在无法解决的循环依赖关系。

  2. downloading openSSL (lite) and placing the 2 dlls (ssleay.dll and libeay.dll) in both the directory where the program is run and the environment/Library/bin. Either one on it's own did not work. Credit for this part goes to this question.