马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
from requests import get
from bs4 import BeautifulSoup as bs
def is_all_chinese(strs):
for _char in strs:
if not '\u4e00' <= _char <= '\u9fa5':
return False
return True
def find_data(res, ip):
soup = bs(res.text, "html.parser")
content = soup.get_text()
index = content.rfind(ip)
content = content[index+len(ip):]
target = ""
for i in content:
if i != "\n":
target += i
else:
break
if is_all_chinese(target.replace(" ", "")):
return target
return "抱歉,找不到您所查找的 IP 地址"
def main(ip):
res = get(f"https://ip.51240.com/{ip}__ip/", ip)
content = find_data(res, ip)
return content
if __name__ == "__main__":
while True:
ip = input("请输入要查询 IP 地址:")
print()
print("地理位置:", main(ip), sep="")
print()
|