2017-11-10 1 views
0

Ich versuche, eine URL aus dem Web zu packen, aber egal was ich tue, es druckt auch das gesamte Modul für die QUrl:PyQt5: Wie ein QUrl ohne die Modulnamen drucken

import sys 
from PyQt5.QtCore import QUrl 
from PyQt5.QtWidgets import QApplication 
from PyQt5.QtWebEngineWidgets import QWebEngineView 

app = QApplication(sys.argv) 
url = 'http://stackoverflow.com' 
wv = QWebEngineView() 

wv.load(QUrl(url)) 
print str(QUrl(url)) 
wv.show() 
app.exec_() 

der gibt mir:

PyQt5.QtCore.QUrl(u'http://stackoverflow.com') 

ich bin nur daran interessiert, die Unicode-String, ohne den Modulnamen Grabbing:

u'http://stackoverflow.com' 

I k Jetzt kann ich nur die URL ausdrucken, aber das ist nur für das Reproduzieren des Problems in einer größeren App.

Antwort

1

Die QUrl Klasse verfügt über eine eigene toString Methode dafür:

>>> u = QtCore.QUrl(u'http://stackoverflow.com') 
>>> u.toString() 
u'http://stackoverflow.com' 

Sie können auch mit Formatting Options in ein Argument übergeben, das wird ändern, wie die URL angezeigt wird (zB durch die Abfrage Entfernen oder Abstreifen folgende Schrägstriche).

+0

danke, es hat funktioniert. u = QUrl (QUrl ((url))) drucken u.toString() –