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

相关推荐
Ulyanov1 分钟前
Pymunk 2D物理游戏开发教程系列 第二篇:约束与关节篇 -《摇摆特技车》
python·架构·系统仿真·雷达电子战·仿真引擎
Trouvaille ~3 分钟前
零基础入门 LangChain 与 LangGraph(三):环境搭建、包安装与第一个 LangChain 程序
python·ai·chatgpt·langchain·大模型·openai·langgraph
喜欢喝果茶.14 分钟前
Qt翻译接口 -逐条翻译(免费级)
开发语言·python
南 阳17 分钟前
Python从入门到精通day60
开发语言·python
不知名的老吴22 分钟前
返回多个值:让函数输出更丰富又不复杂
开发语言·python
larance24 分钟前
python包 解压修改后重新打成whl 包
开发语言·python
2601_9498177228 分钟前
Spring+SpringMVC项目中的容器初始化过程
java·后端·spring
青柠代码录36 分钟前
【SpringBoot】集成 Knife4j
后端
杰克尼37 分钟前
SpringCloud_day04
后端·spring·spring cloud
萤火阳光1 小时前
43|Python 异步生态深度:aiohttp/aiomysql/aioredis 全链路异步实战
开发语言·网络·python