I want to build a web scraper. Currently, I'm learning Python. This is the very basics!
Python Code
import urllib.request
import re
htmlfile = urllib.request.urlopen("http://basketball.realgm.com/")
htmltext = htmlfile.read()
title = re.findall('<title>(.*)</title>', htmltext)
print (htmltext)
Error:
File "C:\Python33\lib\re.py", line 201, in findall
return _compile(pattern, flags).findall(string)
TypeError: can't use a string pattern on a bytes-like object
You have to decode your data. Since the website in question says
charset=iso-8859-1
use that. utf-8 won't work in this case.
htmltext = htmlfile.read().decode('iso-8859-1')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With