這個問題怎么解決啊
>>> 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' 前面加個'b' 試試看
listurl = re.findall(br'http:.+\.jpg', buf) ? ? #python3中urllib.read()返回的是bytes對象
有可能還需要的改動:?
for url in listurl:
????f = open('i' + '.jpg', 'wb') ? ? ? ? ? ? ? ? ? ? ?#用 'wb' 格式打開
? ? url = url.decode('utf-8') ? ? ? ? ? ? ? ? ? ? ? #因為urlopen()需要的是string類型的參數
2016-12-14
謝謝啦