0

A bytes like object is required?

Hi, I've tried this web scraping code: import urllib.request page = urllib.request.urlopen('http://www.robpercival.co.uk/sampledata.html') website = page.read() row_list = website.split("<tr>") print(row_list) However, getting this error --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-3-626463755c02> in <module> 2 page = urllib.request.urlopen('http://www.robpercival.co.uk/sampledata.html') 3 website = page.read() ----> 4 row_list = website.split("<tr>") 5 print(row_list) TypeError: a bytes-like object is required, not 'str' What is wrong?

10/19/2019 9:26:33 AM

Terry

3 Answers

New Answer

+5

or website = str(page.read().decode())

+3

i did a test with type(). it seems that read() is returning byte, not string. add .decode('utf-8') should fix it

0

both methods worked, thanks for the answers!