鱼C论坛

 找回密码
 立即注册
查看: 1769|回复: 1

[作品展示] 查询 IP 地址

[复制链接]
发表于 2020-3-31 15:07:24 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. from requests import get
  2. from bs4 import BeautifulSoup as bs


  3. def is_all_chinese(strs):
  4.     for _char in strs:
  5.         if not '\u4e00' <= _char <= '\u9fa5':
  6.             return False
  7.     return True

  8. def find_data(res, ip):
  9.     soup = bs(res.text, "html.parser")

  10.     content = soup.get_text()

  11.     index = content.rfind(ip)

  12.     content = content[index+len(ip):]

  13.     target = ""

  14.     for i in content:
  15.         if i != "\n":
  16.             target += i

  17.         else:
  18.             break

  19.     if is_all_chinese(target.replace(" ", "")):
  20.         return target

  21.     return "抱歉,找不到您所查找的 IP 地址"


  22. def main(ip):
  23.     res = get(f"https://ip.51240.com/{ip}__ip/", ip)
  24.     content = find_data(res, ip)

  25.     return content

  26. if __name__ == "__main__":
  27.     while True:
  28.         ip = input("请输入要查询 IP 地址:")

  29.         print()
  30.         
  31.         print("地理位置:", main(ip), sep="")

  32.         print()
复制代码

本帖被以下淘专辑推荐:

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-3-31 15:21:22 | 显示全部楼层
自占沙发
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-18 13:42

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表