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

相关推荐
FreakStudio26 分钟前
一文速通 Python 并行计算:13 Python 异步编程-基本概念与事件循环和回调机制
python·pycharm·协程·多进程·并行计算·异步编程
姑苏洛言1 小时前
编写产品需求文档:黄历日历小程序
前端·javascript·后端
姑苏洛言2 小时前
搭建一款结合传统黄历功能的日历小程序
前端·javascript·后端
你的人类朋友2 小时前
🍃认识一下boomi
后端
苏三说技术2 小时前
MySQL的三大日志
后端
豌豆花下猫2 小时前
让 Python 代码飙升330倍:从入门到精通的四种性能优化实践
后端·python·ai
夏末蝉未鸣012 小时前
python transformers库笔记(BertForTokenClassification类)
python·自然语言处理·transformer
南雨北斗3 小时前
TP6使用PHPMailer发送邮件
后端
你的人类朋友3 小时前
🤔什么时候用BFF架构?
前端·javascript·后端
weixin_418813874 小时前
Python-可视化学习笔记
笔记·python·学习