import requests url="http://www.sogou.com" for i in range(20): print("Test %d:" % (i+1),end=" ") response=requests.get(url,timeout=5) if response.status_code==200: print("Conncect successful!") else: print("Conncect UNsuccessful!")
以上是访问Sogou 20次的代码
结果为:
runfile('C:/Users/67377/.spyder-py3/访问.py', wdir='C:/Users/67377/.spyder-py3') Test 1: Conncect successful! Test 2: Conncect successful! Test 3: Conncect successful! Test 4: Conncect successful! Test 5: Conncect successful! Test 6: Conncect successful! Test 7: Conncect successful! Test 8: Conncect successful! Test 9: Conncect successful! Test 10: Conncect successful! Test 11: Conncect successful! Test 12: Conncect successful! Test 13: Conncect successful! Test 14: Conncect successful! Test 15: Conncect successful! Test 16: Conncect successful! Test 17: Conncect successful! Test 18: Conncect successful! Test 19: Conncect successful! Test 20: Conncect successful!