本文整理汇总了Python中PyQt5.QtWebKitWidgets.QWebPage.setNetworkAccessManager方法的典型用法代码示例。如果您正苦于以下问题:Python QWebPage.setNetworkAccessManager方法的具体用法?Python QWebPage.setNetworkAccessManager怎么用?Python QWebPage.setNetworkAccessManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWebKitWidgets.QWebPage
的用法示例。
在下文中一共展示了QWebPage.setNetworkAccessManager方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: webpage
# 需要导入模块: from PyQt5.QtWebKitWidgets import QWebPage [as 别名]
# 或者: from PyQt5.QtWebKitWidgets.QWebPage import setNetworkAccessManager [as 别名]
def webpage(qnam):
"""Get a new QWebPage object."""
from PyQt5.QtWebKitWidgets import QWebPage
page = QWebPage()
page.networkAccessManager().deleteLater()
page.setNetworkAccessManager(qnam)
return page
示例2: Browser
# 需要导入模块: from PyQt5.QtWebKitWidgets import QWebPage [as 别名]
# 或者: from PyQt5.QtWebKitWidgets.QWebPage import setNetworkAccessManager [as 别名]
class Browser(object):
def __init__(self):
self.network_manager = QNetworkAccessManager()
self.network_manager.createRequest = self._create_request
self.network_manager.finished.connect(self._request_finished)
self.web_page = QWebPage()
self.web_page.setNetworkAccessManager(self.network_manager)
self.web_view = QWebView()
self.web_view.setPage(self.web_page)
def _create_request(self, operation, request, data):
print(data.readAll())
reply = QNetworkAccessManager.createRequest(self.network_manager,
operation,
request,
data)
return reply
def _request_finished(self, reply):
if not reply.error() == QNetworkReply.NoError:
# request probably failed
print(reply.error())
print(reply.errorString())
def _make_request(self, url):
request = QNetworkRequest()
request.setUrl(QUrl(url))
return request
def _urlencode_post_data(self, post_data):
post_params = QUrl()
for (key, value) in post_data.items():
post_params.addQueryItem(key, value)
return post_params.encodedQuery()
def perform(self, url, method='GET', post_data=dict()):
request = self._make_request(url)
if method == 'GET':
self.web_view.load(request)
else:
encoded_data = self._urlencode_post_data(post_data)
request.setRawHeader('Content-Type',
QByteArray('application/x-www-form-urlencoded'))
self.web_view.load(request,
QNetworkAccessManager.PostOperation,
encoded_data)
示例3: PageThumbnailer
# 需要导入模块: from PyQt5.QtWebKitWidgets import QWebPage [as 别名]
# 或者: from PyQt5.QtWebKitWidgets.QWebPage import setNetworkAccessManager [as 别名]
class PageThumbnailer(QObject):
"""
Class implementing a thumbnail creator for web sites.
@signal thumbnailCreated(QPixmap) emitted after the thumbnail has been
created
"""
thumbnailCreated = pyqtSignal(QPixmap)
def __init__(self, parent=None):
"""
Constructor
@param parent reference to the parent object (QObject)
"""
super(PageThumbnailer, self).__init__(parent)
self.__page = QWebPage(self)
self.__size = QSize(231, 130)
self.__loadTitle = False
self.__title = ""
self.__url = QUrl()
self.__proxy = NetworkAccessManagerProxy(self)
import Helpviewer.HelpWindow
self.__proxy.setPrimaryNetworkAccessManager(
Helpviewer.HelpWindow.HelpWindow.networkAccessManager())
self.__page.setNetworkAccessManager(self.__proxy)
self.__page.mainFrame().setScrollBarPolicy(
Qt.Horizontal, Qt.ScrollBarAlwaysOff)
self.__page.mainFrame().setScrollBarPolicy(
Qt.Vertical, Qt.ScrollBarAlwaysOff)
# Full HD
# Every page should fit in this resolution
self.__page.setViewportSize(QSize(1920, 1080))
def setSize(self, size):
"""
Public method to set the size of the image.
@param size size of the image (QSize)
"""
if size.isValid():
self.__size = QSize(size)
def setUrl(self, url):
"""
Public method to set the URL of the site to be thumbnailed.
@param url URL of the web site (QUrl)
"""
if url.isValid():
self.__url = QUrl(url)
def url(self):
"""
Public method to get the URL of the thumbnail.
@return URL of the thumbnail (QUrl)
"""
return QUrl(self.__url)
def loadTitle(self):
"""
Public method to check, if the title is loaded from the web site.
@return flag indicating, that the title is loaded (boolean)
"""
return self.__loadTitle
def setLoadTitle(self, load):
"""
Public method to set a flag indicating to load the title from
the web site.
@param load flag indicating to load the title (boolean)
"""
self.__loadTitle = load
def title(self):
"""
Public method to get the title of the thumbnail.
@return title of the thumbnail (string)
"""
return self.__title
def start(self):
"""
Public method to start the thumbnailing action.
"""
self.__page.loadFinished.connect(self.__createThumbnail)
self.__page.mainFrame().load(self.__url)
def __createThumbnail(self, status):
"""
Private slot creating the thumbnail of the web site.
#.........这里部分代码省略.........