Time of Update: 2017-01-19
淘寶官方有擷取商品推廣連結的API,但該API屬於增值API 普通開發人員沒有調用許可權 需要申請開通備忘:登陸採用的是阿里媽媽帳號登陸非淘寶帳號登陸複製代碼 代碼如下:#coding:utf-8__author__ = 'liukoo'import urllib,urllib2,cookielib,refrom hashlib import md5class alimama: def
Time of Update: 2017-01-19
使用re, urllib, threading 多線程抓取天涯文章內容,設定url為需抓取的天涯文章的第一頁,設定file_name為下載後的檔案名稱複製代碼 代碼如下:#coding:utf-8import urllibimport reimport threadingimport os, timeclass Down_Tianya(threading.Thread): """多線程下載""" def
Time of Update: 2017-01-19
環境:【wind2003[open Tftp server] + virtualbox:ubuntn10 server】tftp : Open TFTP Server ubuntn python + pyexpect 採用虛擬機器原因: pyexpect 不支援windows 註:原打算採用secrueCrt 指令碼編寫,因實踐中發現沒有使用linux下pexpect易用,靈活
Time of Update: 2017-01-19
使用python + shell 編寫,是一個簡易solaris系統巡檢程式 複製代碼 代碼如下:#!/usr/bin/python -u#-*- coding:utf-8 -*-'''程式:solaris_status.pyauthor: gyh9711功能: 系統狀態資訊擷取語言: sh + python注意: 部分調用命令需要用到root許可權測試情況: 系統版本:solaris10 系統測試ok 測試伺服器型號:
Time of Update: 2017-01-19
維護指令碼一例,寫得有點亂,只是作為一個執行個體,示範如何快速利用工具快速達到目的:應用到:shell與python資料互動、資料抓取,編碼轉換複製代碼 代碼如下:#coding:utf-8#!/usr/bin/python'''程式說明:apache access.log日誌分析 分析訪問網站IP 來源情況 日期:2014-01-06
Time of Update: 2017-01-19
最近因工作需要,上面要求,每天需上報營運的幾百數通裝置連接埠使用方式【】,雖然有現成網管監控工具監控裝置狀態,但做報表,有點不方便,特寫了個小指令碼。註:測試回合於ubuntn,需安裝snmpwalk工具,目標數通裝置,需做好相關snmp配置複製代碼 代碼如下:#/usr/bin/python#coding:utf-8import os,sysimport refrom pprint import pprint#甯歌鍘傚鏁伴?氳澶嘙IB鍊?MIB = { 'public'
Time of Update: 2017-01-19
一、爬蟲架構Scarpy簡介Scrapy
Time of Update: 2017-01-19
代碼依賴:networkx matplotlib複製代碼 代碼如下: #! /bin/env python# -*- coding: utf-8 -*-import urllibimport urllib2import cookielibimport reimport cPickle as pimport networkx as nximport matplotlib.pyplot as plt__author__ = """Reverland (lhtlyy@gmail.com)""
Time of Update: 2017-01-19
很多情境為了不阻塞,都需要非同步回調機制。這是一個簡單的例子,大家參考使用吧複製代碼 代碼如下:#!/usr/bin/env python# -*- coding: UTF-8 -*-import loggingimport queueimport threadingdef func_a(a, b): return a + bdef func_b(): passdef func_c(a, b, c):
Time of Update: 2017-01-19
就是一個簡單的python查詢百度關鍵詞排名的函數,以下是一些簡介:1、UA隨機2、操作簡單方便,直接getRank(關鍵詞,網域名稱)就可以了3、編碼轉化。編碼方面應該沒啥問題了。4、結果豐富。不僅有排名,還有搜尋結果的title,URL,快照時間,符合SEO需求5、拿來做個軟體或者自己用都很方便。功能是單線程實現,速度慢,大家可以參考修改成自己需要的。複製代碼 代碼如下:#coding=utf-8import requestsimport BeautifulSoupimport
Time of Update: 2017-01-19
單線程實現多個定時器NewTimer.py複製代碼 代碼如下:#!/usr/bin/env pythonfrom heapq import *from threading import Timerimport threadingimport uuidimport timeimport datetimeimport sysimport mathglobal TimerStampglobal TimerTimesclass
Time of Update: 2017-01-19
複製代碼 代碼如下:import time, randomclass GuessNum: def __init__(self): self._num = '' self.input_num = []
Time of Update: 2017-01-19
python最簡潔易懂的掃描連接埠代碼.運行絕對會很有驚奇感複製代碼 代碼如下:from threading import Thread, activeCountimport socketimport osdef test_port(dst,port): os.system('title '+str(port)) cli_sock = socket.socket(socket.AF_INET,
Time of Update: 2017-01-19
一般語言都提供了按字典排序的API,比如跟微信公眾平台對接時就需要用到字典排序。按字典排序有很多種演算法,最容易想到的就是字串搜尋的方式,但這種方式實現起來很麻煩,效能也不太好。Trie樹是一種很常用的樹結構,它被廣泛用於各個方面,比如字串檢索、中文分詞、求字串最長公用首碼和字典排序等等,而且在IME中也能看到Trie樹的身影。 什麼是Trie樹 Trie樹通常又稱為字典樹、單詞尋找樹或首碼樹,是一種用於快速檢索的多叉樹結構。如圖數位字典是一個10叉樹:
Time of Update: 2017-01-19
作業系統:linux軟體環境:Python 2.7.3 用法:複製代碼 代碼如下:$ ./MonSocket.py # This is check the URI or Socket of the script #Usage: ./MonSocket.py -d URL; This is Http protocol ./MonSocket.py -s socket
Time of Update: 2017-01-19
複製代碼 代碼如下:#!/usr/bin/env python# -*- coding: utf-8 -*-import osimport optparseLOCATION_NONE = 'NONE'LOCATION_MID = 'MID'LOCATION_MID_GAP = 'MID_GAP'LOCATION_TAIL =
Time of Update: 2017-01-19
實現了簡單版本的logging.config,支援一般的通過config檔案進行配置。感覺還有更好的方法,是直接利用logging.config.fileConfig(log_config_file)方式讀進來之後,通過修改handler方式來進行修改。複製代碼 代碼如下:"""project trace system"""import sysimport ConfigParserimport loggingimport logging.configimport warningsif
Time of Update: 2017-01-19
調用時輸入參數如: www.jb51.net/表示刪除www.jb51.net首頁的緩衝, www.jb51.net/test.php就表示刪除/test.php的緩衝複製代碼 代碼如下:#coding=utf8import sys,osimport hashlibif len(sys.argv)<2: print("你沒有輸入地址。")
Time of Update: 2017-01-19
以下代碼實現了ip查詢功能處理常式 複製代碼 代碼如下:import os,timedef getip(filepath): ip2city={} file=open(filepath,'r') lines=file.readlines() file.close() for line in
Time of Update: 2017-01-19
近期接手越來越多的東西,發布和營運的工作相當機械,加上頻率還蠻高,導致時間浪費還是優點多。修複bug什麼的,測試,提交版本庫(2分鐘),ssh到測試環境pull部署(2分鐘),rsync到線上機器A,B,C,D,E(1分鐘),分別ssh到ABCDE五台機器,逐一重啟(8-10分鐘) =