这是我在CSDN的第一篇博客,假期刚自学Python,尝试爬取了一下豆瓣top250.希望可以有大佬指点感谢importrequestsfrombs4importBeautifulSoupdefgethtml(url):try:kv={'user-agent':'Mozilla/5.0(WindowsNT10.0;Win64;x64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/59.0.3071.115Safari/
系统 2019-09-27 17:49:53 2144
python中with可以明显改进代码友好度,比如:复制代码代码如下:withopen('a.txt')asf:printf.readlines()为了我们自己的类也可以使用with,只要给这个类增加两个函数__enter__,__exit__即可:复制代码代码如下:>>>classA:def__enter__(self):print'inenter'def__exit__(self,e_t,e_v,t_b):print'inexit'>>>withA()
系统 2019-09-27 17:49:50 2144
前言大部分初学编程的人来说刚开始都会练习判断两个数或者三个数的大小,来熟悉某种语言的特性和最基本的if,else循环,当我们学习了更高级的语法知识后,又会有不同的实现方式,比如这道练习题依次接收用户输入的3个数,排序后打印现在我们来看一下在Python中都有哪些方法来实现:1,采用分支结构,用最基本的if和else来实现:a=int(input('a>>>'))b=int(input('b>>>'))c=int(input('c>>>'))ifa>b:if
系统 2019-09-27 17:49:18 2144
python:如何将excel文件转化成CSV格式importpandasaspddata=pd.read_excel('123.xls','Sheet1',index_col=0)data.to_csv('data.csv',encoding='utf-8')将Excel文件转为csv文件的python脚本#!/usr/bin/envpython__author__="lrtao2010"'''Excel文件转csv文件脚本需要将该脚本直接放到要转换的E
系统 2019-09-27 17:48:54 2144
前言R:代表redis-cliP:代表python的redis准备pipinstallredispool=redis.ConnectionPool(host='39.107.86.223',port=6379,db=1)redis=redis.Redis(connection_pool=pool)redis.所有命令下面命令所有命令我都省略了,有和Python内置函数冲突的我会加上redis.全局命令dbsize(返回key的数量)R:dbsizeP:pr
系统 2019-09-27 17:48:51 2144
withopen("1.txt")asf:whileTrue:line=f.readline()ifnotline:break;print(line.rstrip())
系统 2019-09-27 17:48:48 2144
缘起:[root@CentOS7code]#pythonmulti_thread_mfw.pyFile"multi_thread_mfw.py",line138SyntaxError:Non-ASCIIcharacter'\xe5'infilemulti_thread_mfw.pyonline138,butnoencodingdeclared;seehttp://www.python.org/peps/pep-0263.htmlfordetails写完py
系统 2019-09-27 17:48:24 2144
Golang与python线程详解及简单实例在GO中,开启15个线程,每个线程把全局变量遍历增加100000次,因此预测结果是15*100000=1500000.varsumintvarccccintvarm*sync.MutexfuncCount1(iint,chchanint){forj:=0;j<100000;j++{cccc=cccc+1}ch<-cccc}funcmain(){m=new(sync.Mutex)ch:=make(chanint,1
系统 2019-09-27 17:48:20 2144
0x00:使用xpath进行网页解析#coding:utf-8importrequestsimportosimportrefromlxmlimportetreeimporttimedefget_title(title):#获取标题,创建文件path=r"./Pic/"+titleifos.path.exists(path):#文件夹存在,返回returnpathelse:os.makedirs(path)#创建空文件夹returnpathdefpic_ge
系统 2019-09-27 17:48:14 2144
Python3使用pillow库生成随机验证码的代码如下所示:importrandom#pillow包的使用fromPILimportImage,ImageDraw,ImageFont,ImageFilter#Image负责处理图片#ImageDraw负责处理画笔#ImageFont负责处理文字#ImageFilter负责处理路径img=Image.new('RGB',(150,50),(255,255,255))#建立一个图片'''RGB:表示采用RGB
系统 2019-09-27 17:47:55 2144