
python
文章平均质量分 79
灰暗角落里的琴
一直持续追逐梦想ing...
展开
-
UnicodeDecodeError: 'utf-8' codec can't decode byte
UnicodeDecodeError: 'utf-8' codec can't decode byte 报错。原因:爬取的网站编码和decode默认的utf8编码不同,例如:gbk解决办法:1、忽略掉utf8编码def parse(self, response): print(response.body.decode("utf8", "ignore")) return但这样做的...原创 2018-05-25 22:21:23 · 2374 阅读 · 0 评论 -
python scrapy处理404
class ZfSpider(RedisSpider): handle_httpstatus_list = [404]在自己的代码中,加入handle_httpstatus_list = [404]就可以了。原创 2018-05-30 16:28:19 · 3761 阅读 · 0 评论 -
python3 csv 中文乱码
折腾了好久,终于解决csv存入中文是乱码的情况,直接见代码def writeData(self, movieList): with open('81.csv', 'w', encoding='utf_8_sig', newline='') as f: writer = csv.DictWriter(f, fieldnames=['content']) wri...原创 2018-05-29 18:29:17 · 2405 阅读 · 1 评论 -
python 数组操作
pop:以下实例展示了 pop()函数的使用方法:实例#!/usr/bin/python3#coding=utf-8 list1 = ['Google', 'Runoob', 'Taobao']list_pop=list1.pop(1)print "删除的项为 :", list_popprint "列表现在为 : ", list1以上实例输出结果如下:删除的项为 : Runoob列表现在为 : ...转载 2018-05-29 16:22:10 · 869 阅读 · 0 评论 -
python datetime加减
now = datetime.datetime.now()addda = datetime.timedelta(days=1)newday = now+daysprint newday.strftime('%Y-%m-%d %H:%M:%S')原创 2018-05-29 15:31:21 · 2347 阅读 · 0 评论 -
python 字符串与数组互转
1、str -> array arr = strval.split('')2、array -> strstrval = ''.join(arr)原创 2018-05-29 15:25:48 · 16852 阅读 · 1 评论 -
python 字符串与日期互转
1、str -> dateimport datetimedetester = ‘2017-01-01'date = datetime.datetime.strptime(detester,’%Y-%m-%d')12342、date -> strimport datetimedate = datetime.now()detester = date.strftime(‘%Y-...转载 2018-05-29 15:22:10 · 5123 阅读 · 0 评论 -
python 解析url路径
原理:使用urlparse,先解析整个url,然后使用split('/')方式构造为词典,下面就可以直接读取from urllib.parse import urlparseurl = 'http://www.abc.cn/jfjbmap/content/2016-01/03/node_2.htm'urldic = urlparse(url)print(urldic.path)p...原创 2018-05-29 15:20:01 · 7342 阅读 · 0 评论 -
python scrapy 抓取字符串后一般处理方法源代码
def parse(self, response): selector = Selector(response) data = selector.xpath("//div[@class='header']/div/p")[1] header = data.xpath("string(.)").extract() print(header) info = '...原创 2018-05-29 12:20:43 · 1811 阅读 · 0 评论 -
scrapy中selenium模拟点击下一页代码
class ZufangDownloaderMiddleware(object): # Not all methods need to be defined. If a method is not defined, # scrapy acts as if the downloader middleware does not modify the # passed objec...原创 2018-05-28 08:25:43 · 10226 阅读 · 4 评论 -
python3 中解决"\u8bf7\u6c42\u6210\u529f“格式编码问题
解决方法:def parse(self, response): print(response.body.decode('unicode_escape'))核心就是解码使用unicode_escape原创 2018-05-25 22:58:29 · 65022 阅读 · 3 评论 -
Fiddler "creation of the root certificate was not successful”
网络原文:https://blog.youkuaiyun.com/dassh/article/details/50961362http://localhost:8888/ 安装证书,如果提示没有证书(8888是你在Tool->Fiddler Option->Connections设置的Fiddler监听端口)cd "d:\Program Files\Fiddler"makecert.exe -...转载 2018-05-30 17:10:17 · 209 阅读 · 0 评论