编写python程序,我在使用该urllib.urlopen函数时想出了这个错误.
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)
Run Code Online (Sandbox Code Playgroud)
urlopen(url)返回类似文件的对象.要获取字符串内容,请尝试
CPs = CPs + urllib.urlopen(url).read()
Run Code Online (Sandbox Code Playgroud)