python将IIS日志导入到SQL

摘要: import reimport osimport MySQLdb as mdbdef create_table(name): #建表函数 create_sql = ''' #建表的SQL语句 create table if not exists %s ( ID int primary key auto_increment, DATE date, TIME time, URL text, IP char(15), UA text, REFERER text, STATUS int(3), BYTES int ) ... 阅读全文
posted @ 2013-03-11 22:30 alexkh 阅读(530) 评论(0) 推荐(0) 编辑

python获取IP归属地

摘要: #coding=utf-8import urllib2 #导入urllib2import simplejson #导入simplejsonip = '122.94.240.206' #要查询的IP地址url = 'http://ip.taobao.com/service/getIpInfo.php?ip=%s' % ip #查询的淘宝APIf = urllib2.urlopen(url).read() #通过API获得信息,格式为str#print f s = simplejson.loads(f) #将str格式转化为dict#print sprint  阅读全文
posted @ 2013-03-07 16:47 alexkh 阅读(1640) 评论(0) 推荐(0) 编辑

将IIS中网站日志批量导入到mysql【python】

摘要: import MySQLdb as mdb#info = ['', '2012-7-15', '0:00:25', '/index.html', '114.80.102.172', '-', '200', '0']con = mdb.connect('localhost', 'root', 'root', 'dream')cursor = con.cursor()def insertdata(info): 阅读全文
posted @ 2013-03-06 22:26 alexkh 阅读(498) 评论(0) 推荐(0) 编辑

python批量文件重命名

摘要: import osimport rerootdir= r'D:\rizhi\gp-2012-11'pat = re.compile(r'google.*?(\d{8}).*?\.txt')for n in os.listdir(rootdir): match = pat.match(n) if match: oldname = os.path.join(rootdir, n) newname = os.path.join(rootdir, ('gp' + match.group(1) + '.txt')) os.rename(ol 阅读全文
posted @ 2013-03-05 10:57 alexkh 阅读(298) 评论(0) 推荐(0) 编辑

python2.7 MySQLdb模块在win32下安装

摘要: 参考了这个文章:http://www.crazyant.net/2012/06/08/mysql-python-windows%E4%B8%8Bexe%E5%AE%89%E8%A3%85%E6%96%87%E4%BB%B6%E4%B8%8B%E8%BD%BD/已经有牛人做了exe自动安装程序,MySQL-python-1.2.3.win32-py2.7.exe的下载地址在这里:http://www.codegood.com/archives/129。里面还有64位的下载地址。 阅读全文
posted @ 2013-02-21 09:30 alexkh 阅读(172) 评论(0) 推荐(0) 编辑

python随机生成彩票号码

摘要: 看了oschina的一段代码,于是也模仿了下。原文地址是:http://www.oschina.net/code/snippet_41847_2226我模仿的代码如下:#coding=utf-8import randomdef xuanhao(total, count): element = [x+1 for x in range(total)] result = [] for i in range(count): res = element[random.randint(0, len(element) - 1)] element.remove(r... 阅读全文
posted @ 2013-02-20 16:06 alexkh 阅读(522) 评论(0) 推荐(0) 编辑

《python核心编程》课后题第二版第十五章463页

摘要: 15-1.识别下列字符串:bat、bit、but、hat、hit或hut。import res = raw_input('Enter>> \n')pat = '.*?([bh][aiu]t).*'m = re.match(pat, s)if m: print m.group(1)else: print 'no match'15-2.匹配用一个空格分隔的任意一对单词,比如名和姓。import res = raw_input('Enter>> \n')pat = '.*?(\w+ \w+).*' 阅读全文
posted @ 2013-02-03 18:35 alexkh 阅读(204) 评论(0) 推荐(0) 编辑

python 获取文件版本号和修改时间

摘要: 根据老婆的需求做的小程序:遍历文件夹下所有文件,如果有版本号则加入版本号,如果没有版本号则加入修改时间。最后返回一个字典,key是路径,value是版本号/修改时间。具体代码如下:import osimport os.pathimport win32apiimport timedef getFileName(rootdir): file = [] for parent, dirnames, filenames in os.walk(rootdir): for f in filenames: file.append([parent, f]) ... 阅读全文
posted @ 2013-01-31 23:21 alexkh 阅读(2765) 评论(0) 推荐(0) 编辑

Python-网站日志分析

摘要: 针对自己的网站日志分析做了个小插件:import timeli = [['robots', 'robots.txt', 0], ['pd_1', '-Catalog/', 0], ['pd_2', '/catalog/', 0], ['qp1_1', '/hot-china-products/', 0], ['qp1_2', '/find-china-products/', 0], ['qp2', '-ns/&# 阅读全文
posted @ 2013-01-29 23:46 alexkh 阅读(701) 评论(0) 推荐(0) 编辑

百度收录批量查询【python版】

摘要: import urllib2from BeautifulSoup import BeautifulSoupimport randomimport timedef checkIndex(url): url = url.replace('http://', '') baiduUrl = 'http://www.baidu.com/s?wd=' + url webPage = urllib2.urlopen(baiduUrl) webCont = webPage.read() webCont = webCont.replace('<b&g 阅读全文
posted @ 2013-01-17 23:38 alexkh 阅读(572) 评论(0) 推荐(0) 编辑