简体   繁体   中英

how can I setting the user-agent when in pyside6 WebEngineView

I wrote a Windows software in python and pyside6, in which I opened an interface with QwebEngine, is there any way to define the information such as this embedded browser request header

here are my code of this part

self.webEngineView = QWebEngineView()
self.initialUrl = 'http://www.bing.com'
self.webEngineView.load(QUrl(self.initialUrl))
self.right_bottom_layout.addWidget(self.webEngineView, 0, 0)

but in windows appplication the web interface is too big is to big and I want to show a mobile web page

enter image description here

You would just need to load a QWebEngineHttpRequest with the modified user agent header instead of a url

for example

from PySide6.QtWebEngineCore import QWebEngineHttpRequest


self.webEngineView = QWebEngineView()
self.initialUrl = 'http://www.bing.com'


user_agent = b"Mozilla/5.0 (Android 7.0; Mobile; rv:54.0) Gecko/54.0 Firefox/54.0"
request = QWebEngineHttpRequest()
request.setUrl(self.initialUrl)
request.setHeader(b'user-agent',user_agent)


self.webEngineView.load(request)
self.right_bottom_layout.addWidget(self.webEngineView, 0, 0)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM