這個(gè)問(wèn)題怎么解決啊
>>> listurl = re.findall(r'src=.+\.jpg',buf)
Traceback (most recent call last):
? File "<pyshell#18>", line 1, in <module>
? ? listurl = re.findall(r'src=.+\.jpg',buf)
? File "D:\Python\lib\re.py", line 213, in findall
? ? return _compile(pattern, flags).findall(string)
TypeError: cannot use a string pattern on a bytes-like object
2016-12-14
'r' 前面加個(gè)'b' 試試看
listurl = re.findall(br'http:.+\.jpg', buf) ? ? #python3中urllib.read()返回的是bytes對(duì)象
有可能還需要的改動(dòng):?
for url in listurl:
????f = open('i' + '.jpg', 'wb') ? ? ? ? ? ? ? ? ? ? ?#用 'wb' 格式打開(kāi)
? ? url = url.decode('utf-8') ? ? ? ? ? ? ? ? ? ? ? #因?yàn)閡rlopen()需要的是string類(lèi)型的參數(shù)
2016-12-14
謝謝啦