python3 爬虫时遇到问题:cannot use a string pattern on a bytes-like object
来源:互联网 发布:星游记网络大电影 编辑:程序博客网 时间:2024/05/03 10:26
//交互模式下import reimport urllib.request //python3req = urllib.request.urlopen('www.baidu.con')buf = req.read()buf = bur.decode('utf-8') //python3list = re.findall(r"http:.+\.jpg", buf)i = 0for url in list: f = open(str(i)+'.jpg', 'w') req = rullib.request.urlopen(url) buf = req.read() f.write(buf) i+=1ls
代码中有注释部分均为Python3 学爬虫时需要注意的
1.TypeError: cannot use a string pattern on a bytes-like object 这种情况解决方法就是加上
buf = bur.decode('utf-8')
2.AttributeError: module ‘urllib’ has no attribute ‘urlopen’这种情况的解决办法就是将urllib改成urllib.request就行了
阅读全文
0 0
- python3 爬虫时遇到问题:cannot use a string pattern on a bytes-like object
- 网站地图爬虫章节遇到 TypeError: cannot use a string pattern on a bytes-like object
- Python学习笔记:学习爬虫时遇到的问题TypeError: cannot use a string pattern on a bytes-like object 与解决办法
- TypeError: cannot use a string pattern on a bytes-like object解决方法
- 一劳永逸解决:TypeError: cannot use a string pattern on a bytes-like object
- _compile(pattern, flags).findall(string) TypeError: cannot use a string pattern on a bytes-like
- Python 出现 can't use a string pattern on a bytes-like object
- can't use a string pattern on a bytes-like object
- Python 出现 can't use a string pattern on a bytes-like object
- TypeError: can't use a string pattern on a bytes-like object
- python中‘can't use a string pattern on a bytes-like object’错误
- TypeError:can't use a string pattern on bytes-like object
- can't use a string pattern on a bytes-like object错误和must be str, not bytes错误
- python3 TypeError: a bytes-like object is required, not 'str'
- python3 TypeError: a bytes-like object is required, not 'str'
- python3中,socket使用send函数时出现的错误:TypeError: a bytes-like object is required, not 'str'
- 解决python3的pickle.load错误:a bytes-like object is required, not 'str'
- Python中“a bytes-like object is required, not 'str'”的问题
- 使用位运算总结(转载)
- kafka2:性能优化
- jq鼠标经过隐藏当前显示另一个
- python逻辑控制
- Delphi 動態創建控件,賦值,使用
- python3 爬虫时遇到问题:cannot use a string pattern on a bytes-like object
- css复习整理(三):盒子模型
- 经验分享 | 一个程序员的运气有多重要
- Web自动化测试中针对图片验证码问题的常见解决思路,看看对您有没有帮助
- 完美运动框架
- iOS 通用链接(UniversalLinks)+ 分享功能的一些看法
- ArrayBlockingQueue源码分析
- Python
- 评论平台