gpt4 book ai didi

JavaScript 网页的 Python 抓取仅对 https 页面失败

转载 作者:太空狗 更新时间:2023-10-29 17:51:23 28 4
gpt4 key购买 nike

我正在使用 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()

对于安全页面,脚本返回一个空白页面。唯一返回的 html 是 <html><head></head><body></body></html> .

我有点不知所措。是否缺少与处理安全 URL 相关的设置?

最佳答案

如果您使用的是 Windows,请尝试以下操作: Build PyQt5 on Windows with OpenSSL support?

您是否考虑过使用 Beautiful SoupScrapy.

我在我的项目中使用了 Beautiful Soup,效果非常好。它也支持 SSL。

关于JavaScript 网页的 Python 抓取仅对 https 页面失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39804034/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com