# 多线程把六个网站写到文件里(串行)
import requests,time,threading
def write_html(url,name):
r = requests.get(url)
with open(name,‘w‘,encoding = ‘utf8‘) as f:
f.write(r.text)
urls =[‘www.nnzhp.cn‘,‘www.besttest.cn‘,‘www.imdsx.cn‘,‘sb.nnzhp.cn‘,‘bbs.besttest.cn‘,‘video.besttest.cn‘]
start_time = time.time()
for url in urls: # 循环每个url
new_url = ‘http://‘ + url #六个网站
file_name = url + ‘.html‘ # 写入的六个html文件
write_html(new_url,file_name) # 串行
end_time = time.time()
print(‘程序总共运行了‘, end_time - start_time)