因此,我正在尝试使用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()没有输出。
帮助?
发布于 2013-07-03 00:40:29
我猜您正在开发一个PyQt应用程序,而“licensey”是您从某个“QTextEdit”元素中获取的输入。
在你的应用程序中,'url‘的类型是'QString’。并且在“QString”数据类型中没有“strip”方法。因为open()方法期望你发送一个'str‘类型的参数,你只需要对变量'url’进行类型转换。
只需添加这一行
url = str(url)在调用方法open(url)之前。希望这能有所帮助:)
发布于 2014-10-25 03:19:01
奇怪的是,PyQt QString没有包含()方法,但是它有一个trimmed()方法来做同样的事情。请看这里:http://pyqt.sourceforge.net/Docs/PyQt4/qstring.html#trimmed。PyQt中真正缺少的是变体lstrip()和rtrip()。
https://stackoverflow.com/questions/7748172
复制相似问题