我的python小程序

来源:互联网 发布:淘宝男装店铺便宜 编辑:程序博客网 时间:2024/04/30 06:13

#encoding=utf-8
import os,tempfile,urllib2
import thread
import time,random
import MySQLdb
#获得url内容,并返回内容
def getURLContent(url):
 Content=''
 for line in urllib2.urlopen(url):
  Content=Content+line
 return Content
#将字符串内容写入文件
def fwrite(path,content):
 f=open(path,'w')
 f.write(content)
 f.close()
#开启一个线程
def worker():
 for i in range(2):
  time.sleep(random.randint(10,500)/1000.0)
  print thread.get_ident()
#
#启两个线程 分别运行两次worker
for i in range(2):
 thread.start_new_thread(worker,())
 
time.sleep(1)
#fwrite('/var/www/aa.html',getURLContent('http://zg.sac.net.cn/publicmain?type=1')); 

原创粉丝点击