Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: cannot concatenate 'str' and 'instance' objects (python urllib)

Tags:

python

urllib

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)
like image 373
codygman Avatar asked May 31 '26 21:05

codygman


1 Answers

urlopen(url) returns a file-like object. To obtain the string contents, try

CPs = CPs + urllib.urlopen(url).read()
like image 70
unutbu Avatar answered Jun 02 '26 10:06

unutbu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!