写了一个检测网站服务器的脚本跑着跑着就不跑了,刚开始线程多大跑多快!到后来就会越来越慢,在到最后直接不跑了!怎么能解决?谢谢大佬们!代码如下
#!/usr/bin/python3
import requests
import time
from multiprocessing import Pool
def server(url):
try:
url1=url.strip()
res=requests.get(url=url1)
res2 = (res.headers['Server'])
if "Apache" in res2:
print("该网址是 Apache:{0}".format(url.strip()))
f=open("apache.txt","a")
f.write(url.strip()+"\n")
f.close()
else:
print("其他站点")
fx=open("noapache.txt","a")
fx.write(url.strip()+"\n")
fx.close()
except:
print("网络")
fb=open("no1.txt","a")
fb.write(url.strip()+"\n")
fb.close()
if __name__=="__main__":
urls = ['{}'.format(str(i)) for i in open("urls.txt")]
pool = Pool(processes=20)
pool.map(server, urls)
1
cz5424 2020-06-10 20:00:07 +08:00 via iPhone
大家快来帮我写需求,写完了我就可以下班了
|
2
cz5424 2020-06-10 20:02:39 +08:00 via iPhone
把 get 设置个超时
|
3
axiuluolaitext OP @cz5424 3q 已解决
|
4
MarkLeeyun 2020-06-11 08:39:25 +08:00
爬虫啊,啊哈哈哈哈。
|