Python web-scraping error - TypeError: can't use a string pattern on a bytes-like object -
i want build web scraper. currently, i'm learning python. 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 homecoming _compile(pattern, flags).findall(string) typeerror: can't utilize string pattern on bytes-like object
you have decode data. since website in question says
charset=iso-8859-1 use that. utf-8 won't work in case.
htmltext = htmlfile.read().decode('iso-8859-1') python-3.x web-scraping scraper findall
No comments:
Post a Comment