类型错误:无法连接“str"和“instance"对象(python urllib) [英] TypeError: cannot concatenate 'str' and 'instance' objects (python urllib)
本文介绍了类型错误:无法连接“str"和“instance"对象(python urllib)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
编写一个python程序,在使用urllib.urlopen
函数时出现了这个错误.
Writing a python program, and I came up with this error while using the urllib.urlopen
function.
Traceback (most recent call last):
File "ChurchScraper.py", line 58, in <module>
html = GetAllChurchPages()
File "ChurchScraper.py", line 48, in GetAllChurchPages
CPs = CPs + urllib.urlopen(url)
TypeError: cannot concatenate 'str' and 'instance' objects
url = 'http://website.com/index.php?cID=' + str(cID)
CPs = CPs + urllib.urlopen(url)
推荐答案
urlopen(url) 返回一个类似文件的对象.要获取字符串内容,请尝试
urlopen(url) returns a file-like object. To obtain the string contents, try
CPs = CPs + urllib.urlopen(url).read()
这篇关于类型错误:无法连接“str"和“instance"对象(python urllib)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文