python文件读取和写入案例

python文件读取和写入案例 直接上代码吧都是说明百度上找了很多,最终得出思路没有直接可以读取修改的扩展,只能先读取,然后复制一份,然后在复制出来的文件里面追加保存然后删除读的那个,但是缺点是有的部分样式会缺失#-*-coding:utf-8-*-importxlrd#excel读取扩展库fromdatetimeimportdatetimefromxlrdimportxldate_as_tuple#excel追加修改扩展库fromxlutils.copyimportcopy#wind接口文件fromWindPyimport*w.start();#读写文件分开readfile='1.xls'writefile='2.xls'#执行读文件data=xlrd.open_workbook(readfile)table=data.sheets()[0]#文件复制excel=copy(data)nrows=table.nrows#获取表的行数foriinrange(nrows):#循环逐行打印ifi==0:#跳过第一行continuecode=table.row_values(i)[2...

python第一个爬虫的例子抓取数据到mysql,实测有数据

python3.5先安装库或者扩展1requests第三方扩展库 pip3installrequests2pymysqlpip3installpymysql3lxmlpip3installlxml4 贴个代码#!/usr/bin/envpython#coding=utf-8importrequestsfrombs4importBeautifulSoupimportpymysqlprint('连接到mysql服务器...')db=pymysql.connect("localhost","root","root","python")print('连接上了!')cursor=db.cursor()cursor.execute("DROPTABLEIFEXISTSCOLOR")sql="""CREATETABLECOLOR(ColorCHAR(20)NOTNULL,ValueCHAR(10),StyleCHAR(50))"""cursor.execute(sql)hdrs={'User-Agent':'Mozilla/5.0(X11;Fedora;Linuxx86_64)A...

DUBBO本地搭建及小案例

DUBBO的介绍部分我这里就不介绍了,大家可参考官方文档。DUBBO的注册中心安装DUBBO的注册中心支持好几种,公司用到zookeeper注册中心,所以我这边只说明zookeeper注册中心如何安装。安装zookeeper注册中心首先得下载zookeeper。大家可到zookeeper的官网http://zookeeper.apache.org/releases.html上去下载。我下载了zookeeper-3.4.5.tar.gz版本的包。接下来把zookeeper-3.4.5.tar.gz解压到文件夹D:zookeeper-3.4.5中,然后将zoo_sample.cfg改名为zoo.cfg。然后将配置文件zoo.cfg改成如下:#ThenumberofmillisecondsofeachticktickTime=2000#Thenumberofticksthattheinitial#synchronizationphasecantakeinitLimit=10#Thenumberofticksthatcanpassbetween#sendingarequestandgettin...
代码星球 代码星球·2021-02-11

swing版网络爬虫-丑牛迷你采集器2.0

swing版网络爬虫-丑牛迷你采集器2.0http://www.javacoo.com/code/704.jhtml 整合JEECMShttp://bbs.jeecms.com/fabu/31867.jhtml...

cas sso ajax的jsonp实现方案总结(新浪微薄、淘宝案例分析)

Cas自定义登录页面Ajax实现:http://cydiay.iteye.com/blog/1738713CAS之跨域Ajax登录实践:http://denger.iteye.com/blog/1119233新浪微博如何实现SSO的分析:http://www.iteye.com/topic/1039052淘宝如何跨域获取Cookie分析:http://www.iteye.com/topic/1000776 如果以上网页不能访问,则看下面的网页整页截图:二:  三:四:  ...
代码星球 代码星球·2021-02-11

python爬虫之小说爬取

废话不多说,直接进入正题。今天我要爬取的网站是起点中文网,内容是一部小说。首先是引入库fromurllib.requestimporturlopenfrombs4importBeautifulSoup然后将网址赋值html=urlopen("http://read.qidian.com/chapter/dVQvL2RfE4I1/hJBflakKUDMex0RJOkJclQ2.html")//小说的第一章的网址bsObj=BeautifulSoup(html)//创建beautifulsoup对象首先尝试爬取该页的小说内容firstChapter=bsObj.find("div",{"class","read-content"})//find方法是beautifulsoup对象拥有的函数,print(firstChapter.read_text())find方法也可以和正则表达式搭配使用,并且多用于图片,视频等资源的爬取 由于本次爬取内容全在一个class属性值为read-content的盒子中,所以采用了find方法,如果该网页中,文字被放在多个盒子里,则应采用findAll...
代码星球 代码星球·2021-02-09

canvas 时钟案例

<!doctypehtml><html><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,user-scalable=no,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0"><metahttp-equiv="X-UA-Compatible"content="ie=edge"><title>Document</title><style>#c{background:#ccc;}</style></head><body><canvasid="c"width="400"height="400"></canvas></body></html><script>varcd=document.getElementById("c");varc=c...
代码星球 代码星球·2021-02-08

canvas 方块旋转案例

<!doctypehtml><html><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,user-scalable=no,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0"><metahttp-equiv="X-UA-Compatible"content="ie=edge"><title>Document</title><style>#c{background:#ccc;}</style></head><body><canvasid="c"width="400px"height="400px"></canvas></body></html><script>vard=document.getElementById("c");var...
代码星球 代码星球·2021-02-08

canvas万花筒案例

<!DOCTYPEhtml><html><head><metacharset="UTF-8"><title>Title</title><style>#c{background:#ccc;}</style></head><body><canvasid="c"width="600"height="600"></canvas></body></html><script>vard=document.getElementById("c");varc=d.getContext("2d");vararr=[];//创建方块vart=setInterval(function(){varrects={augle:0,start:150,scale:1,color:"rgb("+Math.random()*255+","+Math.random()*255+","+Math.random()*255+")"};arr.push(...
代码星球 代码星球·2021-02-08

心形陀螺案例css3

<!DOCTYPEhtml><htmllang="zh-cn"><head><metacharset="UTF-8"><title>Title</title><style>body{background:#000;}.box{width:300px;height:300px;margin:200pxauto;-webkit-perspective:1500px;position:relative;}.div{width:150px;height:250px;position:absolute;transform-style:preserve-3d;animation:name2slinearinfinite;transform:rotateY(0deg);}@-webkit-keyframesname{from{transform:rotateY(0deg);}to{transform:rotateY(360deg);}}.div>div{width:140px;height:240px;posi...
代码星球 代码星球·2021-02-08

圆周运动的css3特效案例

<!doctypehtml><htmllang="zh-cn"><head><metacharset="UTF-8"><title>圆周运动的css3特效</title><style>.box{width:300px;height:300px;margin:200pxauto;position:relative;-webkit-perspective:1500px;}.div{width:300px;height:300px;position:absolute;transform-style:preserve-3d;animation:name8slinearinfinite;transform:rotateX(0deg)rotateY(0deg);}@-webkit-keyframesname{from{transform:rotateX(0deg)rotateY(0deg);}to{transform:rotateX(360deg)rotateY(360deg);}}.div>div{widt...

cookie.js插件的案例

  cookie.js插件的案例:  https://github.com/jaywcjlove/cookie.js/blob/master/README.md  文档 api  在这里即可查看用法  <!DOCTYPEhtml>  <html>    <head>      <metacharset="UTF-8">      <title></title>      <scriptsrc="../js/cookie.js"></script>    </head>    <body>      名字:<inputtype="text"name="name"id="name"/><br/>      密码:<inputtype="text"name="pass"id="pass"/><br/>      <buttonid="cun">存cookie<...
代码星球 代码星球·2021-02-08

小人行走的动画案例

  小人行走动画的案例:  <!DOCTYPEhtml>  <html>    <head>      <metacharset="UTF-8">      <title></title>      <style>        *{          margin:0;          padding:0;        }        .div{          width:200px;          height:180px;          position:absolute;          top:100px;          left:100px;          background:url(01.png)no-repeat;                    /*背景...
代码星球 代码星球·2021-02-08

无缝轮播的案例 及css3无缝轮播案例

  无缝轮播的案例:  <!DOCTYPEhtml>  <html>  <head>    <metacharset="UTF-8">    <title>无缝轮播</title>    <style>      *{        margin:0;        padding:0;      }      div{        width:1000px;        height:200px;        position:relative;        top:20px;        left:100px;        border:red5pxsolid;        overflow:hidden;      }      ul{        width:2000px;        height:200px;        list-style:none;        position:absolute;        top:0;        left:-1020px...
代码星球 代码星球·2021-02-08

懒加载(延迟加载的案例)(单张案例)(多张案例

  //单张图片的案例  <!DOCTYPEhtml>  <html>    <head>      <metacharset="UTF-8">      <title></title>      <style>        .a{        width:200px;        height:200px;        margin:1000pxauto;        background:#ccc;        }        .aimg{        width:100%;        height:100%;        }      </style>    </head>    <body>      <divclass="a">        <imgxsrc="img/1.jpg"/>      </div>    </body>  </html><script>...
首页上一页...23456...下一页尾页