Time of Update: 2016-06-06
一、相關代碼資料庫配置類 MysqlDBConn.py 代碼如下:#encoding=utf-8'''Created on 2012-11-12Mysql Conn串連類'''import MySQLdbclass DBConn: conn = None #建立和資料庫系統的串連 def connect(self): self.conn = MySQLdb.connect(host="localhost",port=3306,user="house",
Time of Update: 2016-06-06
環境Python 2.7.6,BS4,在powershell或命令列均可運行。請確保安裝了BS模組 代碼如下:# -*- coding:utf8 -*-# 2013.12.36 19:41 wnlo-c209# 抓取dbmei.com的圖片。from bs4 import BeautifulSoupimport os, sys, urllib2# 建立檔案夾,昨天剛學會path = os.getcwd() # 擷取此指令碼所在目錄new_path = os.path.join(
Time of Update: 2016-06-06
一、相關代碼資料庫配置類 MongoDBConn.py 代碼如下:#encoding=utf-8'''Mongo Conn串連類'''import pymongoclass DBConn: conn = None servers = "mongodb://localhost:27017" def connect(self): self.conn = pymongo.Connection(self.servers) def close(self):
Time of Update: 2016-06-06
直接上代碼了 代碼如下:import smtplibmsg = MIMEMultipart()#構造附件1att1 = MIMEText(open('/home/a2bgeek/develop/python/hello.py', 'rb').read(), 'base64', 'gb2312')att1["Content-Type"] = 'application/octet-stream'att1["Content-Disposition"] = 'attachment; filename="
Time of Update: 2016-06-06
代碼如下:#!/usr/bin/env/ python#coding=utf-8import mechanizeimport cookielib# Cookie Jarcj = cookielib.LWPCookieJar()# Browserbr = mechanize.Browser()br.set_cookiejar(cj)# Browser
Time of Update: 2016-06-06
大家都知道,linux裡一切皆為檔案,在linux/unix的根目錄下,有個/proc目錄,這個/proc 是一種核心和核心模組用來向進程(process)發送資訊的機制(所以叫做“/proc”),這個偽檔案系統允許與核心內部資料結構互動,擷取有關進程的有用資訊,在運行中(on the fly)改變設定(通過改變核心參數)。與其他檔案系統不同,/proc 存在於記憶體而不是硬碟中。proc 檔案系統提供的資訊如下:•進程資訊:系統中的任何一個進程,在 proc
Time of Update: 2016-06-06
代碼如下:import timeimport tkinter as tkclass Window: def __init__(self, title='nms', width=300, height=120, staFunc=bool, stoFunc=bool): self.w = width self.h = height self.stat = True self.staFunc = staFunc
Time of Update: 2016-06-06
代碼如下:#!/usr/bin/env Python import os def load_stat(): loadavg = {} f = open("/proc/loadavg") con = f.read().split() f.close() loadavg['lavg_1']=con[0] loadavg['lavg_5']=con[1] loadavg['lavg_15']=con[2] loadavg['nr']=
Time of Update: 2016-06-06
linux系統使用python擷取cpu資訊指令碼分享 代碼如下:#!/usr/bin/env Pythonfrom __future__ import print_functionfrom collections import OrderedDictimport pprintdef CPUinfo(): ''' Return the information in /proc/CPUinfo as a dictionary in the following format:
Time of Update: 2016-06-06
1 將下面代碼拷貝到一個檔案,命名為asyncore.py 代碼如下:import socketimport selectimport sysdef ds_asyncore(addr,callback,timeout=5): s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) s.connect(addr) r,w,e = select.select([s],[],[],timeout) if r:
Time of Update: 2016-06-06
代碼如下:# -*- coding: cp936 -*-from scapy.all import *from threading import Thread,Lock,activeCountBROADCASTMAC = getmacbyip('192.168.0.120')class Loop(Thread): def __init__(self,ip): Thread.__init__(self) self.ip = ip def run(self):
Time of Update: 2016-06-06
代碼如下:# -*- coding: cp936 -*-from scapy.all import *from threading import Thread,activeCountfrom random import randintclass Loop(Thread): def __init__(self,remoteAddr): Thread.__init__(self) self.remoteAddr = remoteAddr def
Time of Update: 2016-06-06
tcp.py 代碼如下:# -*- coding: cp936 -*-import socketfrom struct import *from time import ctime,sleepfrom os import systemsystem('title tcp sniffer')system('color 05')# the public network interfaceHOST = socket.gethostbyname(socket.gethostname())#
Time of Update: 2016-06-06
系統內容:VC6 +
Time of Update: 2016-06-06
昨天翻硬碟,找到一個好東西,可惜自己加了密碼自己不記得了。試了幾個常用的沒試出來,於是寫了這麼個小指令碼來替我嘗試。。呵呵,還真給解出來了。python指令碼內容如下,跑跑自己加密的壓縮包還不錯 代碼如下:# -*- coding: utf-8 -*-import sys,osdef IsElementUniq(list): """ 判斷list中的元素是否為唯一的 """ for word in list: if
Time of Update: 2016-06-06
代碼如下:#-*-coding:utf-8-*-'''Created on 2014年1月10日@author: hhdys'''import urllib.request,http.cookiejar,reclass Baidu: def login(self): cj = http.cookiejar.CookieJar() opener =
Time of Update: 2016-06-06
熟悉Java的jsoup包的話,對於Python的BeautifulSoup庫應該很容易上手。 代碼如下:#coding: utf-8import sysimport urllibimport urllib2from BeautifulSoup import BeautifulSoupquestion_word = "吃貨 程式員"url = "http://www.baidu.com/s?wd=" +
Time of Update: 2016-06-06
代碼如下:#! /usr/bin/python2.7# -- coding:utf-8 --import os, urllib,urllib2, thread,threadingimport re#匹配音樂urlreg=re.compile('{"name":"(.+?)".+?"rawUrl":"(.+?)",.+?}', re.I)class downloader(threading.Thread): def __init__(self, url, name):
Time of Update: 2016-06-06
代碼如下:# encoding:utf-8### 檔案名稱如:# 下吧.mp3##import os,refs=os.listdir('xb')for f in fs: ######方法一:partition擷取無用字元 #1.將檔案名稱以'['符分為3部分 #ls=f.partition('[') #2.ls[0]為需要檔案名稱,因此擷取ls[1:] #dirtystring = ''.join(ls[1:]) #3.開始替換 #newname=f.replace(dirtystring, '
Time of Update: 2016-06-06
方法一: 代碼如下:f = open("foo.txt") # 返回一個檔案對象 line = f.readline() # 調用檔案的 readline()方法 while line: print line, # 後面跟 ',' 將忽略分行符號 # print(line, end = '') # 在 Python 3中使用 line = f.readline()