import requests import json import time while True: header = {"accept":"application/json, text/javascript, */*; q=0.01","user-agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"} resp = requests.get("https://ip.cn/api/index?ip=&type=0",headers=header) rs = json.loads(resp.text) print("当前IP:"+rs["ip"]) time.sleep(10)