• flask查询工具


    fist_index.html

    <!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>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    searchPhone.py

    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页面里的 手机号码
        data=get_phone(phone3)
        #return phone3
        #return data #原始data是个列表,有时候浏览器不能直接展示列表,会报错
        return '
    '
    .join(data)#原始data是个列表,有时候浏览器不能直接展示列表,会报错 app.run(debug=True)
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39

    展示:
    在这里插入图片描述

    13811701935
    测吉凶(
    )
    中国移动
    010
    101100

  • 相关阅读:
    记录:R语言生成热图(非相关性)
    Java经典面试题汇总:异常
    epoll使用与原理
    yarn的安装与配置(Windows/macOS)
    elementui实现图片和表单信息同时上传
    《算法竞赛进阶指南》蚯蚓
    babel原理
    【C语言】指针和数组笔试题解析(1)
    HamsterBear 构建可启动的镜像(更新中)
    kubectl 速查手册
  • 原文地址:https://blog.csdn.net/xing2516/article/details/132867039