所以我尝试使用 Python 中的 mechanize.Browser() 模块读取网页。问题是 br.open(url) 不起作用,因为 python 返回标题中的错误。
代码如下:
url = "http://www.myserver.com/prda.php?validate=" + licensey
readurl = br.open(url).read()
在最后一行,我得到:
File "/usr/lib/python2.7/urllib.py", line 1038, in unwrap
url = url.strip()
AttributeError: 'QString' object has no attribute 'strip'
我尝试使用 unicode(readurl)、unicode (br.open(url).read())、readlines() 而不是 read()、str (代替 unicode)...我要么得到相同的错误,或 br.open.read() 无输出
帮忙?
最佳答案
我猜您正在开发一个 PyQt 应用程序,“licensey”是您从某些“QTextEdit”元素获取的输入。
在您的应用程序中,“url”的类型为“QString”。并且“QString”数据类型中没有“strip”方法。由于 open() 方法要求您发送“str”类型的参数,因此您只需对变量“url”进行类型转换即可。
只需添加一行
url = str(url)
在调用方法 open(url) 之前。希望这有帮助:)
关于python - “QString”对象没有属性 'strip' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7748172/