在使用pycharm爬取网页内容的时候,出现了TypeError: expected string or bytes-like object 错误

检查之后发现

因为:
re.findall(pattern,string,flag)
这里pattern匹配的是字符串,但是前面获得的html 是类型为bytes,只要将它转化为string类型就好了,如下:

代码就能正常运行:

TypeError: expected string or bytes-like object
最新推荐文章于 2024-09-10 15:18:49 发布
本文介绍在使用PyCharm进行网页爬取时遇到的TypeError: expected string or bytes-like object错误及其解决方法。错误源于re.findall函数中pattern与string类型的不匹配,html内容为bytes类型,需转换为string。
1万+

被折叠的 条评论
为什么被折叠?



