Reputation: 977
# -*- coding: cp949 -*-
import urllib.request
import re
url="http://google.co.kr"
value=urllib.request.urlopen(url).read()
par='<title>(.+?)</title>'
result=re.findall(par,value)
print(result)
In this code I met Error in line 8
"TypeError: can't use a string pattern on a bytes-like object" And
"File"C:\Python34\lib\re.py", line 210, in findall"
Help me please.
Upvotes: 0
Views: 66
Reputation: 90919
urllib.request.urlopen().read()
returns byte-string. You will need to decode()
it to get the string, Example -
value=urllib.request.urlopen(url).read().decode('cp949')
Used cp949 since you seem to be using that in your header - # -*- coding: cp949 -*-
, you can use any encoding you want, you can also leave it blank, so the it gets decoded using the default encoding.
Upvotes: 1