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

相关推荐
鸡鸭扣44 分钟前
Docker:3、在VSCode上安装并运行python程序或JavaScript程序
运维·vscode·python·docker·容器·js
paterWang1 小时前
基于 Python 和 OpenCV 的酒店客房入侵检测系统设计与实现
开发语言·python·opencv
东方佑1 小时前
使用Python和OpenCV实现图像像素压缩与解压
开发语言·python·opencv
神秘_博士2 小时前
自制AirTag,支持安卓/鸿蒙/PC/Home Assistant,无需拥有iPhone
arm开发·python·物联网·flutter·docker·gitee
Moutai码农3 小时前
机器学习-生命周期
人工智能·python·机器学习·数据挖掘
小白教程4 小时前
python学习笔记,python处理 Excel、Word、PPT 以及邮件自动化办公
python·python学习·python安装
武陵悭臾4 小时前
网络爬虫学习:借助DeepSeek完善爬虫软件,实现模拟鼠标右键点击,将链接另存为本地文件
python·selenium·网络爬虫·pyautogui·deepseek·鼠标右键模拟·保存链接为htm
代码猪猪傻瓜coding5 小时前
关于 形状信息提取的说明
人工智能·python·深度学习
Asthenia04126 小时前
如何在项目中集成GC日志输出与高效分析?一篇开发者必读的实践指南
后端
码界筑梦坊6 小时前
基于Flask的第七次人口普查数据分析系统的设计与实现
后端·python·信息可视化·flask·毕业设计