爬虫python3:TypeError: cannot use a string pattern on a bytes-like object
import re
from common_p3 import download def crawl_sitemap(url):
sitemap = download(url)
links = re.findall('<loc>(.*?)</loc>',sitemap)
print('links=',links)
for link in links:
print('link=',link)
html = download(link)
return crawl_sitemap('http://example.webscraping.com/sitemap.xml') TypeError: cannot use a string pattern on a bytes-like object (主要是版本问题)
对于python3x
'sitemap = download(url)'应改为‘sitemap = download(url).decode('utf-8')’
爬虫python3:TypeError: cannot use a string pattern on a bytes-like object的更多相关文章
- TypeError: cannot use a string pattern on a bytes-like object的解决办法
#!/usr/python3 import re import urllib.request def gethtml(url): page=urllib.request.urlopen(url) ht ...
- 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 ...
- Python3 TypeError: initial_value must be str or None, not bytes
response.read() returns an instance of bytes while StringIO is an in-memory stream for text only. Us ...
- python3 pycurl 出现 TypeError: string argument expected, got 'bytes' 解决方案
用pycurl请求指定链接并返回结果时出现 TypeError: string argument expected, got 'bytes' 错误 经过排查问题出现在使用StringIO的write ...
- Symbols of String Pattern Matching
Symbols of String Pattern Matching in Introduction to Algorithms. As it's important to be clear when ...
- Python 出现 can't use a string pattern on a bytes-like object
Python 出现 can't use a string pattern on a bytes-like object 学习了:https://www.cnblogs.com/andrewleeeee ...
- int preg_match( string pattern
preg_match -- 进行正则表达式匹配.并且只匹配一次,注意与preg_match_all区别. int preg_match( string pattern, string subject ...
- 转 python3中SQLLIT编码与解码之Unicode与bytes
#########sample########## sqlite3.OperationalError: Could not decode to UTF-8 column 'logtype' with ...
- 关于TypeError: strptime() argument 1 must be str, not bytes解析
关于TypeError: strptime() argument 1 must be str, not bytes解析 在使用datetime.strptime(s,fmt)来输出结果日期结果时, ...
随机推荐
- 2.Redis 控制短信重发
需要两个缓存 key名称 phone-busy,缓存1分钟key名称 phone-send-count,缓存1天,每成功发送一条+1 发送的时候流程如下: 判断phone-busy是否存在,存在直接报 ...
- 【前端】仿消息推送到App提示
效果: JS: (function ($) { $.fn.loopmsg = function (options, param) { if (typeof options == 'string') ...
- 深浅拷贝 set集合
数据类型的补充 编码转换 # s1 = '中国' # b1 = s1.encode('utf-8') # # print(b1)-------------->b'\xe4\xb8\xad\xe5 ...
- 2019-02-03 线性表的顺序储存结构C语言实现
#include<cstdio> #define MAXSIZE 20 typedef int Elemtype; //Elemtype类型根据实际情况而定,这里取int typedef ...
- (一)Log4j使用
原文链接:https://www.jianshu.com/p/eb4ac2571c94?tdsourcetag=s_pctim_aiomsg 1.先创建个maven项目,在我们项目的pom文件中导入l ...
- @Results用法总结
MyBatis中使用@Results注解来映射查询结果集到实体类属性. (1)@Results的基本用法.当数据库字段名与实体类对应的属性名不一致时,可以使用@Results映射来将其对应起来.col ...
- Docker镜像与容器的常用操作
Docker镜像加速配置:Docker镜像常用操作:Dcoker容器常用操作. 镜像加速器 国内从 Docker Hub 拉取镜像有时会遇到困难,此时可以配置镜像加速器.国内很多云服务商都提供了国内加 ...
- django drf插件(一)
复习 """ 1.vue如果控制html 在html中设置挂载点.导入vue.js环境.创建Vue对象与挂载点绑定 2.vue是渐进式js框架 3.vue指令 {{ }} ...
- 云计算课程实验之安装Hadoop及配置伪分布式模式的Hadoop
一.实验目的 1. 掌握Linux虚拟机的安装方法. 2. 掌握Hadoop的伪分布式安装方法. 二.实验内容 (一)Linux基本操作命令 Linux常用基本命令包括: ls,cd,mkdir,rm ...
- 平时自己常用的git指令
增删改查 创建标签 $ git tag -a v1.4 -m 'my version 1.4' 用 -a (译注:取 annotated 的首字母)指定标签名字即可 -m 选项则指定了对应的标签说明 ...