#!/usr/python3 import re import urllib.request def gethtml(url): page=urllib.request.urlopen(url) html=page.read() return html def getimg(html): reg = r'src="(.*?\.jpg)"' img=re.compile(reg) html=html.decode('utf-8') # python3 imglist=re.findall…
一劳永逸解决:TypeError: cannot use a string pattern on a bytes-like object TypeError: cannot use a string pattern on a bytes-like object python2和python3之间切换,难免会碰到一些问题,有些方法比如re模块的findall要求传入的是字符串格式的参数,urllib.request.urlopen(url).read()返回的是bytes类型(这个是python3…
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('ht…
遇到以下错误的解决办法: 在cell加个setCellType()方法就可以了 cell.setCellType(CellType.STRING);…
尝试将结构化的json数据发送到es(elastic search)上,然后创建视图,这样就能以小时维度查看数据,直接使用post发送到es后,创建索引,结果提示 没有date类型的字段(field).经过一番搜索和请教同事同学,最后尝试如下方法解决: 删除原有的索引,然后在发送数据到ES前的时候先 发送如下请求(es 5.0版本): http://yourhost.com/yourindex/   发送post 或者put请求,请求内容 { "mappings": { "你…
原因:一般出现这个问题是因为数据库中的某个字段的长度小,而插入数据大解决:修改表结构,使表字段大小相同或大于要插入的数据…
Symbols of String Pattern Matching in Introduction to Algorithms. As it's important to be clear when discussing the problem of string matching, we can use the meticulous symbols used in Introduction to Algorithms. Text: $T[1, ..., n]$. Pattern: $P[1,…
Running gulp gives “path.js:7 throw new TypeError('Path must be a string. Received ' + inspect(path));” 百思不得其解,最后还是在万能的 stackoverflow 找到解决办法,特此记录一下 我的Node.js版本太高了,6.9.1,卸载后重新安装 4.2.4版本,npm,gulp,bower,yo等用到组件重新装一遍,执行 gulp serve:dist 成功…
Python 出现 can't use a string pattern on a bytes-like object 学习了:https://www.cnblogs.com/andrewleeeeee/p/6444906.html data = data.decode('utf-8')…
用pycurl请求指定链接并返回结果时出现 TypeError: string argument expected, got 'bytes'  错误 经过排查问题出现在使用StringIO的write方法上,用BytesIO替代StringIO即可解决问题,代码如下:…