pyqt4 - Set QWebView to mobile dimensions -
i trying crawl pages on site mobile user. set user agent match iphone, , trying set dimensions match 320x568. after that, want take screenshot can see pages like, , make sure correct. however, it's desktop view. how can set qwebview
or qwebpage
mobile dimensions when load specific page?
below self.qweb
qwebview
. saw this question using qmainwindow
, headless crawl, , works great is, except setting width & height of "browser" view. tried variations of it, waiting page load, , resetting size, it's not working.
if hasattr(self, 'height') , hasattr(self, 'width'): size = self.qweb.page().mainframe().contentssize() self.qweb.resize(320, 568) self.qweb.setpage(self.page()) self.qweb.loadfinished.connect(self.loaded_page)
update tried well, after page loaded, qsize returned 980x568. tried same function calls in loaded_page
method after page loads, didn't work either. resets view larger size when action on page performed.
self.qweb.setpage(self.page()) self.qweb.page().setviewportsize(qtcore.qsize(320, 568)) self.qweb.page().setpreferredcontentssize(qtcore.qsize(320, 568)) self.qweb.loadfinished.connect(self.loaded_page) def loaded_page(self): # returns qsize(980,568) size = self.qweb.page().mainframe().contentssize()
this page
setup
class page(qwebpage): """qwebpage implementation custom user agent string""" def __init__(self): qwebpage.__init__(self) # settings s = self.settings() s.setattribute(qwebsettings.autoloadimages, true) s.setattribute(qwebsettings.javascriptcanopenwindows, true) s.setattribute(qwebsettings.pluginsenabled, true)
it sounds need set preferred contents size:
page.setpreferredcontentssize(qtcore.qsize(320, 568))
but if doesn't give right results, try setting viewport size:
page.setviewportsize(qtcore.qsize(320, 568))
Comments
Post a Comment