主要为了装个B,统计栏目页面数量时候用的,多线程基本照抄 http://www.cnblogs.com/fnng/p/3670789.html
关于对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()