自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(38)
  • 收藏
  • 关注

原创 python程序打包成exe执行程序并执行

参考:https://www.cnblogs.com/valorchang/p/11357358.html1.pyinstaller工具pyinstaller -F -i text.ico -w mytext.py #这里的-w是用于打包成独立文件,不能进行交互pyinstaller -F -i text.ico mytext.py #打包出来的exe中类似input的交互函数会生效2.py2exe开始执行exe文件报错:1.找不到requests模块解决:1)先查看本地是否有

2021-07-14 16:18:19 195

原创 python中的线程和进程使用

线程基础import threading #线程库import timeimport queueclass myThread(threading.Thread): #继承线程库里面的Thread类 def __init__(self,threadname,threadid,waittime): '''线程名,线程id,等待执行时间''' threading.Thread.__init__(self) #必须要有这句 没有的话就报错 se

2021-04-06 16:11:45 137

原创 unittest模块使用

首先要知道,一个完整的单元测试流程:完整单元测试流程:1.写好一个完整的TestCase类2.多个TestCase 由TestLoder被加载到TestSuite里面, TestSuite也可以嵌套TestSuite3.由TextTestRunner来执行TestSuite,测试的结果保存在TextTestResult中 TestFixture指的是环境准备和恢复testcase类完善1.确定需要测试的模块#需要测试下面这两个方法def myadd(a,b): return

2021-04-06 11:35:34 152

原创 python中多种调用其他指令的方式

# -*- coding:UTF-8 -*-import sys,osimport subprocessvaluea="bob"valueb="say some thing!!"command="echo 'hello world'"os.system(command) #返回值为0则成功with os.popen(command,'r') as a: #返回值是文件对象 print(a.read())a=os.popen(command,'r')print(a.read()

2021-03-24 10:56:01 91

原创 selenium实现免密登录的几种方式

1.设置数据目录免登陆通过数据目录免登陆:设置后,driver.get时先手动输入密码登录,再次打开网页时就不需要输入密码了2.通过获取cookie免登陆https://www.cnblogs.com/blogofzxf/p/10566322.html例:将cookie存放在文件内,加载文件失败时,执行自动登录操作并保存cookie,这样就不用每次都登录了直接执行:loadcookies()...

2021-02-24 16:04:02 1922

原创 shell实现杀掉父进程下的所有子进程

fn_kill_process(){ local process_id="$1" #父进程 echo "process id: $process_id"#ps --ppid 父进程id #查询父进程下的所有子进程 local sub_process_id=$(ps --ppid ${process_id} | awk '{if($1~/[0-9]+/) print $1}') echo "sub process id: ${sub_process_id}" i

2021-02-22 16:13:04 1656

原创 shift方式检查传入参数是否为空

function a(){ haveP="pass" while [ $# -ne 0 ] do if [ -z $1 ];then haveP="false" fi shift done if [ $haveP == "false" ];then echo "have empty paramater!!!!" fi}

2021-02-22 15:54:07 65

原创 shell中实现多种计算方式

第一种: expr 2 + 7 #注意空格不能少 否则报错;只能计算整数第二种: echo "2 + 7" |bc #bc用来计算,可以计算小数 echo "scale=3; 8/3" |bc #scale指定小数点位数为3第三种: echo $(( 2 + 7 )) #一定要空格第四种: echo $[ 2 + 7 ] #同3 ...

2021-02-22 15:08:09 149

原创 grep指令使用

1.完整匹配整个字符串grep -w "spe" a.txt #-w表示精确匹配将spe作为完整字符的行 ==grep -E "\<spe\>" a.txt 2.整行匹配字符串grep -x "test" a.txt #整行匹配字符串3.忽略特殊字符进行匹配grep -Fx "yangchangchun@adc.com" a.txt #查找邮箱字符串#F:将含有特殊字符的看成一个整体 ;X:exact 整行匹配,相当于-w4.匹配文件夹下包含字符的所有文件gre

2021-02-22 14:30:57 512

原创 awk指令使用

1.正常使用awk -F ":" '{print $1}' a.txtCat a.txt |awk '/inet/ {split($2,x,":");print x[2]}' #获取有inet的行 用:对第2个字符分割放入x数组中awk '{gsub(/ /,"")1}' a.txt #去掉空格awk '{gsub(/\$/,"");gsub(/,/,"");cost+=$4;}END{print "The sum is $"cost > "filename"}' awk_file

2021-02-22 14:21:06 214

原创 xargs的使用

1.格式化:cat a.txt |xargs |cut -d : -f 2-2.配合find使用find . -type f -maxdepth 1 -name "*.cfg"|xargs -i cat {} #找出来的文件集体进行cat获取内容find . -type f -maxdepth 1 -name "*.cfg"|xargs -i rm -rf {} #找出来的文件集体进行删除find . -type d -maxdepth 1 -not -name "*jfrog"|xar

2021-02-22 11:48:30 90

原创 sed使用

参考:https://segmentfault.com/a/1190000015885994sed -i #操作直接修改文件内容sed -n #仅仅输入后面操作的内容sed -e #按照后面处理其中: d 为删除 a为新增 p为打印sed "s/b/a/g" a.txt #a字符替换b字符,g表示全局替换; 这里是只打印替换后的内容 不影响a文件内容sed -i "s/b/a/g" a.txt #替换内容并写入a文件echo "12345-m23994" |

2021-02-22 11:39:32 337

原创 sort指令使用

a.txt内容:a;73;2a;123b;23;cc;324c;1;cc;21jk;124;j;45sort -t ";" -k 2 -n a.txt #-t 指定分割符号;-k 表示用第几位作为排序的;-n 表示将排序的作为数字 这样才能排序;-u 排序的时候保持唯一,去除重复行;-r 倒叙排序...

2021-02-22 11:35:13 190

原创 expect实现远程操作

expect工具使用:先确保机器上已安装该工具#!/bin/bashmachine_ip=$1password="**"username="aa" #使用expect工具expect << EOF spawn ssh $username@$machine_ip expect "password:" send "$password" #发送密码进行登录 expect "#" send "echo 'hello $machine_ip@!!!!!!' " ex

2021-02-22 11:33:37 144

原创 selenium基础使用

from selenium import webdriverimport time#声明浏览器对象chromeDriver = 'C:\driver\chrome\chromedriver.exe'driver=webdriver.Chrome(chromeDriver)#访问页面(html源码)url="https://www.qidian.com/"driver.get(url)html=driver.page_source#拖拽操作from selenium.webdrive

2021-02-22 11:28:30 98

原创 shell实现替换空格

去除空格:a="12 jk 234 eikal"echo $a |sed 's/[[:space:]]//g'echo $a |sed "s/ //g" #成功echo $a |cut -d " " --output-delimiter="" -f 1- #成功 不能少了-fecho $a |awk '{gsub(/ /,"")}1' #全局替换空格 不会替换换行a=${a// /} #成功 //表示全局替换a=${a/ / } #单斜杠表示从左开始只截取第一个

2021-02-20 09:57:09 3776

原创 openpyxl读取和写入excel文件

采用openpyxl处理# -*- coding:UTF-8 -*-import openpyxl# import pandasdef readwb(): '''读取已经存在的excel文件内容''' xlsx = "./userinfo.xlsx" wb = openpyxl.load_workbook(xlsx) print(wb.worksheets) #读取所有的excel中存在工作表 ##第一种遍历方式 sheet=wb['入职名单']

2021-02-01 15:13:53 410

原创 python处理文件是否可读

if os.path.exists('./a.txt'): print("file exists!") os.remove('a.txt')else: print("file not exists!")path='./mount.xml'if not os.access(path, os.R_OK): # R_OK可读;X_OK 可执行;os.W_OK 文件写权限 print("file not exists or can't read")...

2021-01-28 17:14:00 164

原创 python将jenkins获取的时间转换为正常的年月日显示

from datetime import datetime#将jenkinspipeline中的currentBuild.startTimeInMillis转换为日常使用的时间格式:#a=int(currentBuild.startTimeInMillis)a=1611737708290b=datetime.fromtimestamp(a/1000)c=datetime.fromtimestamp(a/1000).strftime('%Y-%m-%d %H:%M:%S')print(b)pri

2021-01-28 17:07:10 944

原创 python循环字典的两种方式

import sys,osa={"package_server1_url":"/mountpath/server1/path", "package_server1_mount_cmd":"mout 172.*.*.*/server1 /mountpath/server1/path", "package_server2_url":"/mountpath/server2/path", "package_server2_mount_cmd":"mout 172.*.*.*/server1 /

2021-01-28 17:00:23 558

原创 python程序调用shell指令的多种方法

# -*- coding:UTF-8 -*-import sys,osimport subprocessvaluea="bob"valueb="say some thing!!"command="echo 'hello world'"#第一种:os.system()os.system(command) #返回值为0则成功#第二种:os.popen()with os.popen(command,'r') as a: #返回值是文件对象 print(a.read())a=os.p

2021-01-28 16:50:47 71

原创 BeautifulSoup、requests、re模块案例实战:爬取jenkins页面在线机器和离线机器ip并存放入文件

# -*-coding:UTF-8-*-import os, sysimport datetimeimport requestsimport refrom bs4 import BeautifulSoup as bsimport xml.etree.ElementTree as ETif len(sys.argv) < 3: print "参数不足!!请传入url和文件名" exit(1)url = sys.argv[1]filename = sys.ar

2021-01-26 17:05:33 144

原创 python连接数据库:pymsql模块基础操作

import pymysql,os,sysmydb=pymysql.connect(host='localhost',user='root',password='',db='mydb',charset='utf8')cursor=mydb.cursor()try: try: data=(9,'newname','python5',34) sql="insert into mytable values(%d,'%s','%s',%d);" % (data)

2021-01-26 17:03:21 75

原创 html页面解析类:xml(用的是etree下的parse)

参考:https://www.jb51.net/article/63780.htmtree = ET.parse(“country.xml”)import xml.etree.ElementTree as ET tree = ET.parse("country.xml")root = tree.getroot()root.tag for child in root: print child.tag, "---", child.attrib 或者:try: import xml

2021-01-26 17:01:51 283

原创 xml.etree.ElementTree处理xml文件并写入excel

1.city.xml<ruzhi> <time year="2018"> <user username="楠楠" jobname="硬件" cityname="成都"> <hobbit>极限运动</hobbit> </user> <user username="谢科" jobname="芯片" cityname="江西"/> <user username="岳云" jobname="it软件

2021-01-26 16:59:54 344

原创 python下载图片的三种方式

img_url是图片的链接,pic_id+’.jpg’为图片名字(可以指定完整路径)######正常方式下载图片####data=requests.get(img_url).contentwith open(pic_id+'.jpg','wb') as file: file.write(data) #####通过字节流下载图片####with requests.get(img_url,stream=True) as imgbyte: #一直打开图片流 with open(pic_id+'.

2021-01-26 16:55:57 812

原创 python连接数据库:pymsql模块--增删查改操作类化

dbDemon项目目录结构:__init__.py初始化文件 #一个模块必须要的文件config.py 配置文件model.py 具体实现操作的文件dbDemonTest.py 测试db模块的文件config.py 配置文件#定义数据库信息host='localhost'user='root'password=''dbname='mydb'port=3306model.py 具体实现操作的文件import pymysql,os,sysfrom dbDemon import

2021-01-26 16:54:31 111

原创 scrapy爬虫框架基础使用知识

1.确保安装了myscrapy模块(爬虫专用)2.scrapy startproject project_name #创建项目名为project_name的爬出项目3.用编译工具打开爬虫项目,目录有:spiders:在这下面操作爬虫init.py #默认的 不动**.py #自己定义的操作数据的文件items.py #定义需要爬取的数据settings.py:爬虫配置文件middlewares.py #用来对spider返回的item列表进行数据的保存等操作,可以写入文件或保存到数

2021-01-26 16:29:13 67

原创 scrapy案例实战一:jenkins在线和离线节点获取并存入数据库

自定义爬虫文件:jenkinsIP.py# -*- coding: utf-8 -*-import scrapyfrom scrapy import selectorfrom bs4 import BeautifulSoup as bsfrom jenkins_IP.items import JenkinsIpItem# import sys# reload(sys)# sys.setdefaultencode('utf8')import re,datetimeclass Jenki

2021-01-26 16:06:45 313

原创 html页面解析类:lxml(用的是etree下面的xpath)

html=etree.HTML(content)#-*-coding:UTF-8-*-from lxml import etree #xpath是etree内的模块import sysreload(sys)sys.setdefaultencoding('utf8')file=open('a.html','r')content=file.read()html=etree.HTML(content) #将html内容转换为树状结构的可访问内容file.close()####开始读取h

2021-01-25 17:47:11 283

原创 html页面解析类:re模块解析

re模块可以进行替换、匹配、分割等操作 #re模块 正则表达式:匹配 检索 替换 分割用import sys,os,re#####查询 search() match() findall() finditem()######res=re.search("[0-9]",'abscd23') #在后面的字符串查找数字 这里是用的re模块的函数print(res) #<re.Match object; span=(5, 6), match='2'>print(res.group

2021-01-25 17:42:25 545

原创 html页面解析类:BeautifulSoup基础使用

bs4:可以解析为lxml格式,也可以解析为html格式基础使用#-*-coding:UTF-8-*-from bs4 import BeautifulSoupimport os,sysimport json# reload(sys)# sys.setdefaultencoding('utf8')if os.path.exists('a.html'): print "file not exist!!"# excelfile='C:\Users\W9005357\Desktop\g

2021-01-25 17:36:51 209

原创 selenium库:页面获取类

具体请百度

2021-01-25 17:11:09 90

原创 requests案例实战:post方式使用百度翻译

import jsonimport requests##以翻译hello为例###输入查询词,在header处显示的是post方式访问,访问的链接是https://fanyi.baidu.com/sug,response时数据是json格式content-type: application/json,输入的值是kw: hellurl="https://fanyi.baidu.com/sug"data={'kw':'hello'}resp=requests.post(url,data=data

2021-01-25 16:51:49 230

原创 requests库:页面获取类

简单使用import requestsimport reurl="https://shimo.im/docs/CHQt86xJvgp3R8yp"headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36'} #伪装一个浏览器用户resp=requests.get(url,headers

2021-01-25 16:43:46 145

原创 urllib案例实战二:boss职位信息简单获取(re模块使用)

import refrom urllib import request,errorimport timeif __name__ == '__main__': url="https://www.zhipin.com/job_detail/?query=%E9%85%8D%E7%BD%AE%E7%AE%A1%E7%90%86&city=101270100&industry=&position=" headers={'User-Agent':'Mozilla/5.0

2021-01-25 16:28:38 109

原创 urllib操作实战一:post方式访问百度翻译

页面分析获取post的具体网址:获取需要传递的数据代码实现from urllib import parse,request #parse用来转换在post时需要传输的值import json##以翻译hello为例###输入查询词,在header处显示的是post方式访问,访问的链接是https://fanyi.baidu.com/sug,response时数据是json格式content-type: application/json,输入的值是kw: hellurl="http

2021-01-25 16:23:46 492

原创 urllib库:页面获取类

使用的两种方式:1.urllib.request.urlopen()方法直接使用urllib.reuqest.urlopen(url)2.urllib.request.Request类:将url变为一个对象进行操作urlR=urllib.request.Request(url)urllib.request.urlopen(urlR) #打开的是url的对象urllib实例操作一:urllib.error的三种异常处理方式分别有HTTPError 和URLError两种子类import ur

2021-01-25 15:35:47 137

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除