self.setCentralWidget(self.web_view)
self.web_view.loadFinished.connect(self._load_finished)

def _load_finished(self):
    frame = self.web_view.page().mainFrame()
self.web_view.page().setViewportSize(frame.contentsSize())
self.resize(frame.contentsSize())
html_data = frame.toHtml()
if __name__ == '__main__':
    app = QApplication(sys.argv)
browser = Browser()
r = QUrl('http://www.yahoo.com')
browser.web_view.load(r)
browser.show()
app.exec_()
How to set the size of browser using QtWebKit