
python
crayon-shin-chan
这个作者很懒,什么都没留下…
展开
-
记一个jupyterlab-sql版本问题
1.简介安装了最新版本的jupyterlab和jupyterlab-sql,但是没法工作jupyter labextension listJupyterLab v3.1.18Other labextensions (built into JupyterLab) app dir: /home/ubuntu/.local/share/jupyter/lab jupyterlab-sql v0.3.3 enabled X The following exten..原创 2021-10-14 17:44:34 · 395 阅读 · 1 评论 -
scrapy命令行使用
1.帮助scrapy --helpUsage: scrapy <command> [options] [args]Available commands: bench Run quick benchmark test check Check spider contracts crawl Run a spider edit Edit spider fetch Fetch a URL原创 2020-09-09 20:28:35 · 373 阅读 · 0 评论 -
记一个scrapy导入PipeLine问题
1.简介scrapy在Spider中引入PipeLine custom_settings = { 'LOG_LEVEL':'INFO', 'LOG_FILE': 'log/home.log', 'IMAGES_STORE' : '1home/images',#图片存储 'ITEM_PIPELINES': { 'pipeline.HomeImagePipeLine.HomeImagePipeLine': 50.原创 2020-10-19 14:42:39 · 501 阅读 · 0 评论 -
记一个jupyter启用扩展时的错误 PermissionError: [Errno 13] Permission denied: ‘/usr/etc‘
1.简介jupyter安装了扩展,启用扩展时,发现写入目录是/usr/etc,因为没有权限会报错jupyter serverextension enable jupyterlab_sql --py --sys-prefixEnabling: jupyterlab_sql- Writing config: /usr/etc/jupyter...PermissionError: [Errno 13] Permission denied: '/usr/etc'2.解决Pe..原创 2021-10-14 16:20:42 · 973 阅读 · 1 评论 -
python使用matplotlib绘图
1.简介Matplotlib 是 Python 的绘图库。 它可与 NumPy 一起使用,提供了一种有效的 MatLab 开源替代方案。1.1 简单示例import numpy as np from matplotlib import pyplot as plt x = np.arange(1,11) y = 2 * x + 5 plt.title("Matplotlib demo") plt.xlabel("x axis caption") plt.ylab..原创 2020-10-24 23:51:22 · 462 阅读 · 0 评论 -
记一个pymysql Incorrect string value: ‘ xxx“,...‘ for column ‘xxx‘ at row 1问题
1.简介使用pymysql插入数据,显示字符串值不正确2.解决原因有很多,都是字符集问题,我的问题是客户端连接字符串不对:pymysql.connect(self.host, self.username, self.password, self.database, charset='utf8mb4' )虽然建表时字符集是对的,客户端字符集不正确也不行...原创 2020-10-18 12:19:08 · 421 阅读 · 0 评论 -
python使用threading库操作线程
1.示例import threadingdef run(): print("当前线程名称为:"+threading.current_thread().name)thread = threading.Thread(target=run)print("准备运行线程")thread.start()准备运行线程当前线程名称为:Thread-1run:定义一个线程运行方法,可以包含参数 threading.Thread:创建一个线程对象,方法为参数 thread..原创 2020-09-25 21:45:20 · 250 阅读 · 0 评论 -
python使用xml.dom.minidom解析xml
xml文件:<collection shelf="New Arrivals"><movie title="Enemy Behind"> <type>War, Thriller</type> <format>DVD</format> <year>2003</year> <rating>PG</rating> <stars>10</...原创 2020-09-25 21:11:51 · 972 阅读 · 0 评论 -
python使用pymysql操作mysql数据库
1.获取连接import pymysql# 打开数据库连接connect = pymysql.connect("localhost", "root", "123456", "test", charset='utf8' )# 使用cursor()方法获取操作游标 cursor = connect.cursor()version_sql = 'select version()'result = cursor.execute(version_sql) print("执行结果:"+st原创 2020-09-25 20:24:30 · 867 阅读 · 0 评论 -
记一个python logging模块打印日志打印两次、多次的问题
1.简介使用logging模块打印日志,封装了获取logger的方法 #获取指定房间的日志记录器 def get_logger(desk): #获取日志记录器 logger = logging.getLogger(desk) logger.setLevel(logging.INFO) #滚动日志处理器 handler = RotatingFileHandler("log/"+desk+'原创 2020-09-22 22:22:51 · 5220 阅读 · 0 评论 -
记一个scrapy发送POST请求问题
1.问题data= { 'keywords': None, 'channelId': 0, 'channel_id': 0, 'orderFlg': 1,#时间倒排 'pageNoCurrent': 1,#当前页码,从1开始 'isLockChannel': 0}scrapy.FormRequest(url=self.base_url,formdata=原创 2020-09-10 17:27:12 · 711 阅读 · 0 评论 -
python使用multiprocessing操作子进程
1.简介multiprocessing是一个用与threading模块相似API的支持产生进程的包。multiprocessing包同时提供本地和远程并发,使用子进程代替线程,有效避免Global Interpreter Lock带来的影响。因此,multiprocessing模块允许程序员充分利用机器上的多个核心。Unix 和 Windows 上都可以运行。multiprocessing模块还引入了在threading模块中没有类似物的API。这方面的一个主要例子是Poo...原创 2020-09-09 19:45:32 · 528 阅读 · 0 评论 -
python使用subprocess操作子进程
1.简介subprocess 模块允许我们启动一个新进程,并连接到它们的输入/输出/错误管道,从而获取返回值。2.run方法run方法直接运行命令,然后返回一个CompletedProcess对象subprocess.run(args, *, stdin=None, input=None, stdout=None, stderr=None, capture_output=False, shell=False, cwd=None, timeout=None, check=False, .原创 2020-09-09 19:04:36 · 902 阅读 · 0 评论 -
python logging日志模块配置
1.文件加载配置import logging.configfrom os import pathlog_file_path = os.path.join(path.dirname(path.abspath(__file__)), 'log.conf')logging.config.fileConfig(log_file_path)使用logging.config模块加载日志配置文件2.记录器列表[loggers]keys=rootlogger = logging.get.原创 2020-09-09 11:27:05 · 445 阅读 · 0 评论 -
python网络请求库requests的使用
1.get请求import requestsresult = requests.get('https://baidu.com')print(str(result.status_code))GET / HTTP/1.1Host: www.baidu.comUser-Agent: python-requests/2.24.0Accept-Encoding: gzip, deflateAccept: */*Connection: keep-alive2.post表单请求.原创 2020-09-07 19:22:35 · 356 阅读 · 0 评论 -
python3内置re模块操作正则表达式
1.matchre.match 尝试从字符串的起始位置匹配一个模式,如果不是起始位置匹配成功的话,match()就返回nore.match(pattern, string, flags=0)pattern:需要匹配的正则表达式,默认从字符串开头匹配,如果包含匹配组,则从字符串中提取匹配组string:需要匹配的字符串flags:匹配的标志位,是否区分大小写,多行匹配1.1 默认从字符串开头匹配import reprint(re.match('www', 'www.ru.原创 2020-07-27 00:32:58 · 414 阅读 · 0 评论 -
python使用scapy抓取http报文
原始的Scapy对http抓包的支持不够友好,数据包的分割只能到TCP级别,需要编码将TCP包合并为HTTP数据包,操作起来很不方便,这里需要使用一个scapy_http包来支持http的解包from scapy.all import *import scapy_http.httpdef printPacket(packet): if packet.haslayer('HTTP'): print("============================")原创 2020-07-23 15:54:42 · 7729 阅读 · 3 评论 -
win10安装pypcap
pypcap是python的网络抓包库1.下载npcap-sdk下载页面下载到npcap-sdk-1.05,里面包含了pypcap安装需要的头文件和库文件include:头文件目录,拷贝到python安装目录下的includeLib:库文件目录,拷贝到python安装目录下的lib目录,注意64位和32位文件不一样2.下载pypcap仓库git clone git@github.com:crayon-shin-chan/pypcap.git3.安装...原创 2020-07-13 18:49:56 · 1436 阅读 · 0 评论 -
python3内置函数
1.打印内置函数>>> print(dir(__builtins__))['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BlockingIOError', 'BrokenPipeError', 'BufferError', 'BytesWarning', 'ChildProcessError', 'ConnectionAbortedError', 'ConnectionErro原创 2020-07-13 15:16:16 · 156 阅读 · 0 评论 -
python3内置os模块
1.系统属性获取1.1获取当前目录os.getcwd():获取当前工作目录>>> import os>>> print(os.getcwd())D:\software\dev\lang\python\Python381.2获取父目录os.pardir:获取父目录>>> print(os.pardir)..看着很诡异1.3获取文件目录分隔符os.sep:获取文件目录分隔符>>...原创 2020-07-12 23:38:07 · 451 阅读 · 0 评论 -
ubuntu安装pgadmin4
1.命令安装pip install pgadmin4pip3 install pgadmin42.whl安装2.1下载whl文件文件目录2.2安装whl文件pip install pgadmin4-4.9-py2.py3-none-any.whlpip3 install pgadmin4-4.9-py2.py3-none-any.whl3.遇到问题3.1 ImportError: cannot import name 'url_encod...原创 2020-07-05 21:55:50 · 2534 阅读 · 0 评论 -
pip配置阿里云镜像
pip下载包时需要配置阿里云镜像加速1.创建~/.pip/pip.conf2.添加配置内容[global]index-url = http://mirrors.aliyun.com/pypi/simple/[install]trusted-host=mirrors.aliyun.com原创 2020-07-05 17:48:13 · 2170 阅读 · 0 评论 -
python操作HTML标签注释
Python使用爬虫获取文本内容时,经常会发现获取到的文本包含了HTML注释,这时想要去除这些注释,就需要一些方法,自己写逻辑显然比较麻烦而且效果不稳定,这里主要用到了w3lib库的html模块1.remove_tags()移除指定标签,不移除内部文本from w3lib import htmldoc = ''' <div> <a>我是超链接</a> <h1>我是标题</h1> .原创 2020-06-21 23:17:14 · 1263 阅读 · 0 评论 -
python进行URL编码
在浏览器发送请求时会对表单请求数据与查询字符串进行一种URL编码,这种编码旨在将数据中的影响HTTP的字符进行转换,变为HTTP允许的字符,Python使用urllib库进行转换from urllib import parse#数据对象data = { "a":"1", "b":"3", "x":"张三", "y":"李四"}#进行url_encode编码,编码结果为查询字符串形式,即进行url编码,然后用a=1&b=2形式拼接键值对text.原创 2020-06-21 22:48:49 · 20880 阅读 · 0 评论 -
python字节编码(十六进制、base64)
Python有字节编码库binasciiimport binascii#创建字节数组,数组长度必须为偶数,因为两个字符为一个字节a = b'helloworld'print(a)#字节数组转换为十六进制字符串 !!!的字节数组,注意最后,返回值还是字节数组,如果需要转字符串需要decodeprint(binascii.b2a_hex(a))print(binascii.b2a_hqx(a))#字节数组转换为BASE64字符串的字节数组print(binascii.b2a_ba.原创 2020-06-17 12:44:37 · 2381 阅读 · 0 评论 -
python使用scapy进行网络底层操作
1.网络嗅探sniff(iface="QualcommAtherosAR956xWirelessNetworkAdapter",prn=lambdax:x.show())sniff函数可以作为网络嗅探,获取本地网卡的网络包,以下为参数:iface:网卡名称,在windows上没有eth0、eth1等名称,所以要使用ipconfig /all,取获取的网卡信息的描述作为网卡名称prn:打印包的函数filter:抓包过滤器,采用wireshark语法,比如icmp,注意不能大写...原创 2020-06-17 12:29:21 · 1099 阅读 · 0 评论 -
scrapy爬虫ImagePipeLine的自定义扩展
Scrapy框架提供了ImagePipeLine管道,用于下载网页中的图片,存储到本地或者云框架提供的默认管道功能是,在Spider中收集图片url,作为列表存储到Item的指定属性image_urls中去,管道自动会下载图片并且可以存储完整图像和缩略图到指定的存储位置,图片名称为url的hash这里主要有一个问题,图片如果要分类、分详情存储,比如一个详情页面的图片放到一个文件夹中,这样的要求旧需要定制ImagePipeLine1.图片存储Itemimport scrapy# .原创 2020-06-16 07:43:35 · 381 阅读 · 0 评论 -
python可迭代对象
在python中,可以用形如 for a in xxx:形式去遍历的叫可迭代对象,如下#字符串本身为可迭代对象,每个字符为元素print("string iterator")for a in 'dsdsadasdasdas': print(a) #集合也是可迭代对象 print("set iterator")for a in set('dsdsadasdasdas'): print(a) #列表也是可迭代对象 print("list itera.原创 2020-05-19 08:40:47 · 521 阅读 · 0 评论 -
python列表
List(列表) 是 Python 中使用最频繁的数据类型。列表可以完成大多数集合类的数据结构实现。它支持字符,数字,字符串甚至可以包含列表(即嵌套)。列表用[ ]标识,是 python 最通用的复合数据类型。列表中值的切割也可以用到变量[头下标:尾下标],就可以截取相应的列表,从左到右索引默认 0 开始,从右到左索引默认 -1 开始,下标可以为空表示取到头或尾。注意:python列表可以同时包含不同种类元素,比如字符串和数字b=["32","33","34","35...原创 2020-05-19 07:24:18 · 278 阅读 · 0 评论 -
python3 if else 嵌套
if True: print("1") elif True: print("2")else: print("3") elif xxxxxxx原创 2020-05-18 22:59:44 · 286 阅读 · 0 评论 -
python3 print()换行输出
a='x'b='y'#换行输出print(a)print(b)print(a,end="\n")print(b,end="\n")#不换行输出print(a,end="")print(b,end="")主要是print有end参数,而此参数默认为\n原创 2020-05-18 22:56:33 · 1341 阅读 · 0 评论 -
Python3.8.2安装(64位Win10系统)
1.下载安装包在这个页面下载pthon下载页面2.点击安装选择定制安装Advanced Options处不要勾选以下两个选项,因为他们会导致下载错误,这些文件可以在安装后手动下载Download debugging symbolsDownload debug binaries安装直到完毕3.手动下载debug模块文件下载页面debug模块下载页面以_pdb和_d结尾的文件都下载下来4.手动安装debug模块文件下载下来的模块文件都是.msi格...原创 2020-05-10 01:41:51 · 1822 阅读 · 0 评论