爬虫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)来输出结果日期结果时, ...
随机推荐
- 深入理解PHP原理之Opcodes
Opcode是一种PHP脚本编译后的中间语言,就像Java的ByteCode,或者.NET的MSL. 举个例子,比如你写下了如下的PHP代码: <?php echo "Hello Wo ...
- 【 哈希和哈希表】Three Friends【进制哈希】
Three Friends 传送门:链接 (UPC)或 链接(大视野) 题目描述 Three friends like to play the following game. The first f ...
- IP组网实验(使用Cisco Packet Tracer路由器模拟软件)
最近计网课讲到了以太网,第二个计网实验就是IP组网实验.这个实验主要使用了netsim这个路由器模拟软件.怎奈mac上没有,于是用Cisco Packet Tracer进行了一次模拟(其实就是实验中的 ...
- 精美图文讲解Java AQS 共享式获取同步状态以及Semaphore的应用
| 好看请赞,养成习惯 你有一个思想,我有一个思想,我们交换后,一个人就有两个思想 If you can NOT explain it simply, you do NOT understand it ...
- SQL中游标的使用示例
declare @email_source varchar(MAX); --1.原始发件人字段 declare @key_name varchar(50); --2.我方卷号或客户代码 declare ...
- MongoDB文档(二)--查询
(一)查询文档 查询文档可以使用以下方法 # 以非结构化的方式显示所有的文档 db.<collectionName>.find(document) # 以结构化的方式显示所有文档 db.& ...
- C语言宏技巧 X宏
前言 本文介绍下X宏的使用 首先简单介绍下宏的几种用法 #define STRCAT(X,Y) X##Y #define _STR(X) #@X #define STR(X) #X #define L ...
- v-on事件修饰符
.stop阻止冒泡 .prevent阻止默认行为 .capture实现捕获触发事件的机制(从大到小) .self实现只有点击当前元素时,才能出发事件处理函数 .once只触发一次事件函数 .stop和 ...
- 四层发现-TCP发现
直接向目标ip发送一个ACK数据包,正常情况下up状态的目标ip会返回一个SRT数据包. 使用scapy构造TCP数据包: 然后在将一些数据类型设置好就可以发送了. 实用脚本实现批量扫描: #!/us ...
- HTML&CSS面试高频考点(一)
1. 行内元素/块级元素 非替换元素/替换元素 行内元素(内联元素):a, abbr(缩写), acronym(只取首字母缩写), b, bdo(文本方向), big, br, cite(引用), c ...