flask查询工具

fist_index.html

python 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>电话查询工具</title>
</head>
<body>
    <table>
        <form action="/search_phone" method="get">
                手机号码:<input type="text" id="phone" value="phone" name="phone2">
                <input type="submit" id="search" value="查询" name="search">
         </form>
    </table>
</body>
</html>

searchPhone.py

python 复制代码
import requests
from flask import Flask,render_template,request
from lxml import etree#解析数据模块

def get_phone(phone):
    url = f'https://www.ip138.com/mobile.asp?mobile={phone}&action=mobile'
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'

        }  # 伪装浏览器访问,防止网站拒绝访问
    res = requests.get(url, headers=headers)
    res.encoding = 'utf-8'  # 有乱码,显示中文
    # print(res.text)
    # 解析数据
    e = etree.HTML(res.text)
    # 通过xpath拿取数据
    data = e.xpath('//tr/td[2]/a/text()')
    print(data)
    return data


get_phone(13811701936)

##前台页面展示接口
app=Flask(__name__)
@app.route('/index')
def index():
    #return '测试页面展示hahh'
    return render_template('fist_index.html')
@app.route('/search_phone')
def search_phone():
    #return "search_phone接口"
    phone3=request.args.get('phone2')#这里的phone2要和fist_index.html页面里的 手机号码<input 标签里的neme值一致
    data=get_phone(phone3)
    #return phone3
    #return data #原始data是个列表,有时候浏览器不能直接展示列表,会报错
    return '<br/>'.join(data)#原始data是个列表,有时候浏览器不能直接展示列表,会报错

app.run(debug=True)

展示:

13811701935

测吉凶(

)

中国移动

010

101100

相关推荐
毕设源码_钟学姐20 分钟前
计算机毕业设计springboot宿舍管理信息系统 基于Spring Boot的高校宿舍管理平台设计与实现 Spring Boot框架下的宿舍管理系统开发
spring boot·后端·课程设计
运器12321 分钟前
【一起来学AI大模型】PyTorch DataLoader 实战指南
大数据·人工智能·pytorch·python·深度学习·ai·ai编程
音元系统24 分钟前
Copilot 在 VS Code 中的免费替代方案
python·github·copilot
超龄超能程序猿35 分钟前
(5)机器学习小白入门 YOLOv:数据需求与图像不足应对策略
人工智能·python·机器学习·numpy·pandas·scipy
方圆想当图灵1 小时前
ScheduledFutureTask 踩坑实录
后端
全栈凯哥1 小时前
16.Spring Boot 国际化完全指南
java·spring boot·后端
M1A11 小时前
Java集合框架深度解析:LinkedList vs ArrayList 的对决
java·后端
31535669132 小时前
Springboot实现一个接口加密
后端
cooldream20092 小时前
Python 包管理新时代:深入了解 `uv` 的使用与实践
python·uv·包管理器
之歆2 小时前
Python-魔术方法-创建、初始化与销毁-hash-bool-可视化-运算符重载-容器和大小-可调用对象-上下文管理-反射-描述器-二分-学习笔记
笔记·python·学习