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

相关推荐
清水白石0082 小时前
突破并行瓶颈:Python 多进程开销全解析与 IPC 优化实战
开发语言·网络·python
麦麦大数据2 小时前
M003_中药可视化系统开发实践:知识图谱与AI智能问答的完美结合
人工智能·flask·llm·vue3·知识图谱·neo4j·ner
Lupino3 小时前
IoT 平台可编程化:基于 Pydantic Monty 构建工业级智能自动化链路
python
清水白石0084 小时前
突破性能瓶颈:深度解析 Numba 如何让 Python 飙到 C 语言的速度
开发语言·python
yunhuibin6 小时前
AlexNet网络学习
人工智能·python·深度学习·神经网络
喵手7 小时前
Python爬虫实战:增量爬虫实战 - 利用 HTTP 缓存机制实现“极致减负”(附CSV导出 + SQLite持久化存储)!
爬虫·python·爬虫实战·零基础python爬虫教学·增量爬虫·http缓存机制·极致减负
一个处女座的程序猿O(∩_∩)O7 小时前
Python异常处理完全指南:KeyError、TypeError、ValueError深度解析
开发语言·python
was1727 小时前
使用 Python 脚本一键上传图片到兰空图床并自动复制链接
python·api上传·自建图床·一键脚本
好学且牛逼的马7 小时前
从“Oak”到“虚拟线程”:JDK 1.0到25演进全记录与核心知识点详解a
java·开发语言·python
shangjian0077 小时前
Python基础-环境安装-Anaconda配置虚拟环境
开发语言·python