要用移动版的,web版本需要更多参数请求
# coding: utf-8 import requests def Ipdizhi(ip): try: url = "http://m.ip138.com/ip.asp" kv = {"ip": ip} r = requests.get(url, params=kv) print(r.request.url) r.encoding = r.apparent_encoding r.raise_for_status() print(r.text[-500:]) # 显示最后500个字节 except: print("Error") Ipdizhi(str(input()))