1. 程式人生 > 其它 >TypeError: cannot use a string pattern on a bytes-like object

TypeError: cannot use a string pattern on a bytes-like object

技術標籤:pythonpython

問題:

TypeError: cannot use a string pattern on a bytes-like object

解決方式:

def getimg(html):
    reg = r'src="(.*?\.jpg)"'
    img=re.compile(reg)
    # 把html 指定編碼格式,解決問題
  #  html=html.decode('utf-8') # python3
    imglist=re.findall(img,html)