一个账号 发表于 2020-3-31 15:07:24

查询 IP 地址

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

    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()

一个账号 发表于 2020-3-31 15:21:22

自占沙发{:10_248:}
页: [1]
查看完整版本: 查询 IP 地址