import requests
def fetch_and_save(url, filename, verify=False):
    try:
        response = requests.get(url, timeout=5, verify=verify)
        response.raise_for_status()  # 检查请求是否成功
        with open(filename, 'w', encoding='utf-8') as file:
            file.write(response.text)
        print(f"内容已保存到 {filename}")
    except requests.RequestException as e:
        with open(filename, 'w', encoding='utf-8') as file:
            file.write("None")
        print(f"请求 {url} 时出错: {e}")

# 访问HTTP
fetch_and_save(f'http://{ip_address}', 'http.txt')
最后修改:2024 年 05 月 11 日
如果觉得我的文章对你有用,请随意赞赏