SEO工具箱:Python統計欄目頁面數量

主要爲了裝個B,統計欄目頁面數量時候用的,多線程基本照抄 http://www.cnblogs.com/fnng/p/3670789.htmlhtml

關於對SEO有什麼用處。。。我以爲。。。僅對本人有用,Python對SEO仍是特殊的個性需求數組

#coding:utf-8

import urllib,threading
from time import ctime,sleep

def num_1(func):
    for num in range(3,399,2):
        url = 'http://www.xxx.co/paper/list/%s' % num
        status = urllib.urlopen(url).code
        print 'time long:%s' % ctime(),url,status
        sleep(1)

def num_2(func):
    for num in range(2,400,2):
        url = 'http://www.xxx.co/paper/list/%s' % num
        status = urllib.urlopen(url).code
        print 'last time long:%s' % ctime(),url,status
        sleep(5)
    
threads = []
t1 = threading.Thread(target=num_1,args=(u'單數',))
threads.append(t1) #把線程t1裝到threads數組中
# print threads
t2 = threading.Thread(target=num_2,args=(u'雙數',))
threads.append(t2)

if __name__ == '__main__':
    for t in threads: #遍歷數組,數組被裝載了t1和t2
        t.setDaemon(True)
        t.start()

    t.join() #在子線程運行完成以前,這個子線程的父線程將一直被阻塞,join在for循環外,等待兩個進程都結束再執行主線程

    print 'all over %s' % ctime()
相關文章
相關標籤/搜索