import requests import time # pip install -i https://pypi.douban.com/simple/ --trusted-host=pypi.douban.com/simple requests def get(url): res=requests.get(url) result=res.text return result if __name__ == '__main__': url='http://ypt.cfedu.net/dsideal_yy/adminlogin/captchaText' count=0 while True: now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) try: print(get(url)+" "+now+" 错误次数:"+str(count)) time.sleep(5) except Exception as err: count=count+1 print("发生了一些错误"+" "+now) # 打开「detail_content」文件 fout = open('c:/err.txt', 'a', encoding='utf8') # 写入文件内容 fout.write(str(err)) #关闭文件 fout.close() time.sleep(10)