通过beeware制作安卓apk用于获取cpolar网址

我们都知道,没有付费的cpolar用户,要不时更新cpolar网址。每次都要自己登录去获取远程的cpolar个人网址比较麻烦,好在可以用python去自动获取。这里说的是,比如用手机装termux软件,再在termux中装cpolar,然后我用qpython软件制作一个网站,网站的功能是利用qpython的sl4a拍照功能不断拍摄,保存到数据库,以网页显示实现远程监控功能,用qpython中flask开启一个127.0.0.1端口为默认5000的网站,用cpolar穿透到互联网上。然后就回到我一开始说的获取cpolar生成的随机网址。考虑到使用便捷,制作一个安卓程序,装在手机上随时能查看监控的情况。

上面,废话很多,还是具体用到的人就会明白。

一,装briefcase,即beeware。用briefcase new生成一个空间,修改app.py为

"""
qwcy app
"""import toga
from toga.style.pack import COLUMN, LEFT, RIGHT, ROW, Pack
import requests
from bs4 import BeautifulSoup#导入必要的库def fetch_info_from_website(login_url, info_url, credentials, tunnel_name):with requests.Session() as session:try:# 获取登录页面以抓取csrf tokenlogin_page = session.get(login_url)login_page.raise_for_status() # 检查请求是否成功login_page_soup = BeautifulSoup(login_page.text, 'html.parser')# 提取csrf tokencsrf_token = login_page_soup.find('input', {'name': 'csrf_token'})['value']credentials['csrf_token'] = csrf_token# 登录print("登录中,请等待。")login_response = session.post(login_url, data=credentials)# 检查是否登录成功if login_response.status_code != 200 or login_response.url == login_url:print("登录失败,请检查您的凭据。")return []else:print("登录成功。")# 获取信息页面response = session.get(info_url)response.raise_for_status()# 解析页面soup = BeautifulSoup(response.text, 'html.parser')table = soup.find('table')if not table:print("未找到隧道列表,请检查对应设备的cpolar服务和网络连接。")return []links = [] # 用于存储找到的链接for row in table.find_all('tr')[1:]: # 跳过表头cells = row.find_all('td')if len(cells) > 1:tunnel = cells[0].get_text().strip()url_cell = row.find('a', href=True) # 直接在行中查找<a>标签if tunnel == tunnel_name and url_cell:links.append(url_cell['href']) # 添加匹配的链接print(f"找到隧道 {tunnel} 的链接: {url_cell['href']}")return linksexcept requests.RequestException as e:print(f"请求异常: {e}")except Exception as e:print(f"发生错误: {e}")
def build(app):# 定义组件box = toga.Box()webview = toga.WebView(style=Pack(width=600, height=800,padding_left=2))login_url = "https://dashboard.cpolar.com/login"info_url = "https://dashboard.cpolar.com/status"credentials = {'login': '你的号@qq.com','password': '你的密码'}tunnel_name = 'default'links = fetch_info_from_website(login_url, info_url, credentials, tunnel_name)if links:geturl = links[1]else:geturl = '无法获取网址,重新开启'html = f'''<script>    function copyTextToClipboard(text) {{var input = document.createElement('input');document.body.appendChild(input);input.setAttribute('value', text);input.select();var result = document.execCommand('copy');document.body.removeChild(input);return result;}}</script>    <a href='{geturl}'>{geturl}</a><br>{links[0]}<br><button onclick="copyTextToClipboard('{links[0]}')">Copy Url</button>'''webview.set_content("data:text/html", html)# webview.url = geturlbox.add(webview)return boxdef main():return toga.App("查看小孩学习网址", "org.geturl", startup=build)if __name__ == "__main__":main().main_loop()

二,修改pyproject.toml文件。我的为

# This project was generated with 0.3.17 using template: https://github.com/beeware/briefcase-template@v0.3.17
[tool.briefcase]
project_name = "geturl"
bundle = "com.geturl"
version = "0.0.1"
url = "https://geturl.com/geturl"
license = "MIT license"
author = "ybk"
author_email = "eybk@qq.com"[tool.briefcase.app.geturl]
formal_name = "geturl"
description = "geturlapp"
long_description = """More details about the app should go here.
"""
icon = "src/geturl/resources/geturl"
sources = ["src/geturl",
]
test_sources = ["tests",
]requires = ["requests","beautifulsoup4"
]
test_requires = [    "pytest",][tool.briefcase.app.geturl.macOS]
universal_build = true
requires = ["toga-cocoa~=0.4.0","std-nslog~=1.0.0",
][tool.briefcase.app.geturl.linux]
requires = ["toga-gtk~=0.4.0",
][tool.briefcase.app.geturl.linux.system.debian]
system_requires = [# Needed to compile pycairo wheel"libcairo2-dev",# Needed to compile PyGObject wheel"libgirepository1.0-dev",
]system_runtime_requires = [# Needed to provide GTK and its GI bindings"gir1.2-gtk-3.0","libgirepository-1.0-1",# Dependencies that GTK looks for at runtime"libcanberra-gtk3-module",# Needed to provide WebKit2 at runtime# "gir1.2-webkit2-4.0",
][tool.briefcase.app.geturl.linux.system.rhel]
system_requires = [# Needed to compile pycairo wheel"cairo-gobject-devel",# Needed to compile PyGObject wheel"gobject-introspection-devel",
]system_runtime_requires = [# Needed to support Python bindings to GTK"gobject-introspection",# Needed to provide GTK"gtk3",# Dependencies that GTK looks for at runtime"libcanberra-gtk3",# Needed to provide WebKit2 at runtime# "webkit2gtk3",
][tool.briefcase.app.geturl.linux.system.suse]
system_requires = [# Needed to compile pycairo wheel"cairo-devel",# Needed to compile PyGObject wheel"gobject-introspection-devel",
]system_runtime_requires = [# Needed to provide GTK"gtk3",# Needed to support Python bindings to GTK"gobject-introspection", "typelib(Gtk) = 3.0",# Dependencies that GTK looks for at runtime"libcanberra-gtk3-0",# Needed to provide WebKit2 at runtime# "libwebkit2gtk3",# "typelib(WebKit2)",
][tool.briefcase.app.geturl.linux.system.arch]
system_requires = [# Needed to compile pycairo wheel"cairo",# Needed to compile PyGObject wheel"gobject-introspection",# Runtime dependencies that need to exist so that the# Arch package passes final validation.# Needed to provide GTK"gtk3",# Dependencies that GTK looks for at runtime"libcanberra",# Needed to provide WebKit2# "webkit2gtk",
]system_runtime_requires = [# Needed to provide GTK"gtk3",# Needed to provide PyGObject bindings"gobject-introspection-runtime",# Dependencies that GTK looks for at runtime"libcanberra",# Needed to provide WebKit2 at runtime# "webkit2gtk",
][tool.briefcase.app.geturl.linux.appimage]
manylinux = "manylinux_2_28"system_requires = [# Needed to compile pycairo wheel"cairo-gobject-devel",# Needed to compile PyGObject wheel"gobject-introspection-devel",# Needed to provide GTK"gtk3-devel",# Dependencies that GTK looks for at runtime, that need to be# in the build environment to be picked up by linuxdeploy"libcanberra-gtk3","PackageKit-gtk3-module","gvfs-client",
]linuxdeploy_plugins = ["DEPLOY_GTK_VERSION=3 gtk",
][tool.briefcase.app.geturl.linux.flatpak]
flatpak_runtime = "org.gnome.Platform"
flatpak_runtime_version = "45"
flatpak_sdk = "org.gnome.Sdk"[tool.briefcase.app.geturl.windows]
requires = ["toga-winforms~=0.4.0",
]# Mobile deployments
[tool.briefcase.app.geturl.iOS]
requires = ["toga-iOS~=0.4.0","std-nslog~=1.0.0",
][tool.briefcase.app.geturl.android]
requires = ["toga-android~=0.4.0",
]base_theme = "Theme.MaterialComponents.Light.DarkActionBar"build_gradle_dependencies = ["androidx.appcompat:appcompat:1.6.1","com.google.android.material:material:1.11.0",# Needed for DetailedList"androidx.swiperefreshlayout:swiperefreshlayout:1.1.0",
]# Web deployments
[tool.briefcase.app.geturl.web]
requires = ["toga-web~=0.4.0",
]
style_framework = "Shoelace v2.3"

即添加requires = [
"requests",
"beautifulsoup4"
]

三,briefcase create android,briefcase build android生成app-debug.apk,把这个文件发给手机,就安装可以打开。

界面如上,用https才能在app中点进去访问,但不能调网页大小,还是用JavaScript,点击copy url按钮,在手机的浏览器上粘贴后访问。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/diannao/95468.shtml
繁体地址,请注明出处:http://hk.pswp.cn/diannao/95468.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Swift 实战:用链表和哈希表写出高性能的贪吃蛇引擎(LeetCode 353)

文章目录摘要描述解决方案解析问题与解决方案关键细节逐条讲示例与运行结果时间复杂度空间复杂度总结摘要 这题的目标是设计一个“贪吃蛇”核心引擎&#xff1a;给定棋盘大小和一串食物位置&#xff0c;支持不断调用 move(direction) 推进游戏&#xff0c;返回当前分数&#x…

2025-08-15:按对角线进行矩阵排序。用go语言,给你一个 n × n 的整数矩阵,要求返回一个按下面规则调整后的矩阵: - 将每一条与主对角线平行的斜线视为一个序列。对于位于主对角线及其下方的

2025-08-15&#xff1a;按对角线进行矩阵排序。用go语言&#xff0c;给你一个 n n 的整数矩阵&#xff0c;要求返回一个按下面规则调整后的矩阵&#xff1a;将每一条与主对角线平行的斜线视为一个序列。对于位于主对角线及其下方的那些斜线&#xff08;即所在位置的行索引 ≥ …

MySQL相关概念和易错知识点(5)(索引、事务、MVCC)

目录1.索引&#xff08;1&#xff09;局部性原理a.局部性原理在计算机中的地位b.pagec.池化技术&#xff08;Buffer Pool&#xff09;&#xff08;2&#xff09;如何理解索引&#xff08;3&#xff09;索引的原理a.page的构成b.多层目录c.基于B树的索引①B树的特性在索引中的作…

SQLite 子查询

SQLite 子查询 SQLite 是一个轻量级的数据库管理系统&#xff0c;广泛应用于移动设备、嵌入式系统和桌面应用。在处理复杂的查询时&#xff0c;子查询&#xff08;Subquery&#xff09;是SQLite数据库查询语言中的一个强大工具。本文将详细介绍SQLite子查询的概念、用法及其在数…

区块链系统审计方法论:全面指南与Python实践

目录 区块链系统审计方法论:全面指南与Python实践 1. 引言 2. 区块链审计框架 3. 智能合约审计关键技术 3.1 静态代码分析 3.2 符号执行(Symbolic Execution) 4. 共识机制审计 4.1 PoW共识验证 4.2 PBFT共识模拟 5. 数据完整性审计 5.1 Merkle树验证 6. 完整审计系统实现 7.…

分布式锁—Redisson的公平锁

1.Redisson公平锁RedissonFairLock概述 (1)非公平和公平的可重入锁 一.非公平可重入锁 锁被释放后&#xff0c;排队获取锁的线程会重新无序获取锁&#xff0c;没有任何顺序性可言。 二.公平可重入锁 锁被释放后&#xff0c;排队获取锁的线程会按照请求获取锁时候的顺序去获取…

上网行为安全概述和组网方案

一、上网行为安全概述1. 背景与需求互联网的双刃剑特性&#xff1a;网络普及改变工作生活方式&#xff0c;业务向互联网迁移。缺乏管理导致风险&#xff1a;带宽滥用、监管困难、信息泄露、网络违法、安全威胁。核心问题&#xff1a;带宽滥用&#xff1a;P2P/流媒体占用70%带宽…

某处卖600的【独角仙】尾盘十分钟短线 尾盘短线思路 手机电脑通用无未来函数

通达信指标【独角仙】尾盘十分钟套装-主图-副图-选古指标&#xff0c;支持手机电脑使用。在股市收盘的前十分钟第二天冲高卖出&#xff0c;信号可以盘中预警也可以尾盘选股&#xff0c;如果要保证信号固定建议是尾盘选股即可&#xff0c;当天信号固定后&#xff0c;不会产生漂移…

日志数据链路的 “搬运工”:Flume 分布式采集的组件分工与原理

flume详解&#xff1a;分布式日志采集的核心原理与组件解析 在大数据体系中&#xff0c;日志采集是数据处理的第一步。Flume 作为 Apache 旗下的分布式日志采集工具&#xff0c;以高可用、高可靠、易扩展的特性&#xff0c;成为处理海量日志数据的首选方案。本文将从 Flume 的…

大消费新坐标中的淘宝大会员

一站式消费需要一站式权益。作者|古廿编辑|杨舟淘宝的大会员体系落地了。8月6日&#xff0c;淘宝首次整合饿了么、飞猪等阿里系平台资源&#xff0c;推出覆盖购物、外卖、出行、旅游的一体化会员体系——用户在三大平台的消费&#xff0c;都能累积淘气值&#xff0c;根据淘气值…

MIME(多用途互联网邮件扩展)

MIME&#xff08;Multipurpose Internet Mail Extensions&#xff09; MIME 是 多用途互联网邮件扩展 的缩写&#xff0c;它最初是为了解决传统电子邮件只能传输纯文本的局限性而设计的&#xff0c;后来逐渐成为互联网中 数据格式标识与传输 的通用标准&#xff0c;被广泛应用…

PHP imagick扩展安装以及应用

Date: 2025-08-13 10:48:12 author: lijianzhan php_imagick是PHP的一个强大的扩展模块&#xff0c;用于调用ImageMagick图像处理库的功能&#xff0c;支持处理JPEG、PNG、GIF等超过185种格式的图像&#xff0c;实现缩放、旋转、动画生成等操作&#xff0c;常用于网页图片动态生…

2025年度14款CRM销售管理系统横向评测

本文深入对比了以下14款CRM销售管理软件&#xff1a;1.纷享销客&#xff1b; 2.Zoho CRM&#xff1b; 3.红圈销售&#xff1b; 4.销帮帮&#xff1b; 5.Salesforce&#xff1b; 6.Pipedrive&#xff1b; 7.Microsoft Dynamics 365&#xff1b; 8.悟空 CRM&#xff1b; 9.励销云…

akamai鼠标轨迹

各位肯定被akamai鼠标轨迹、点击事件、键盘事件&#xff0c;网页交互困扰 那么我们就研究一下鼠标轨迹、点击事件AST解混淆, 拿到解混淆后的代码&#xff0c; 如下&#xff0c;sensor_data就是我们要搞的参数 如何解混淆这里就不赘述了&#xff0c;需要的可以看我上一篇文章&am…

飞算JavaAI开发全流程解析:从自然语言到可运行工程的智能进化

引言 在数字经济时代&#xff0c;企业级应用开发面临着需求多变、交付周期紧、质量要求高的三重挑战。传统Java开发模式依赖人工进行需求确认、架构设计、代码编写和测试验证&#xff0c;导致开发效率低下、沟通成本高企。据统计&#xff0c;一个中等规模的项目需要平均8周完成…

垃圾回收标记算法:三色标记

文章目录1 三色标记流程1.1 初始标记1.2 并发标记1.3 重新标记1.4 清除阶段&#xff08;Sweep&#xff09;1.5 为什么初始标记和重新标记需要STW&#xff0c;而并发标记不需要?2 并发标记的写屏障3 多标问题4.漏标问题4.1 漏标的两个必要条件4.2 解决方案一&#xff1a;增量更…

反射的详解

目录一、反射1.JDK,JRE,JVM的关系2.什么是反射3. 三种获取Class对象(类的字节码)的方式4.Class常用方法5. 获取类的构造器6.反射获取成员变量&使用7.反射获取成员方法8.综合例子一、反射 1.JDK,JRE,JVM的关系 三者是Java运行环境的核心组成部分&#xff0c;从包含关系上看…

Grafana Tempo日志跟踪平台

以下是Grafana Tempo文档的总结&#xff08;基于最新版文档内容&#xff09;&#xff1a; 核心概念 分布式追踪系统&#xff1a;Tempo是开源的分布式追踪后端&#xff0c;专注于高吞吐量、低成本存储和与现有监控生态的深度集成 架构组成&#xff1a; Distributor&#xff1a…

Qt基本控件

Qt 的基本控件是构建用户界面的基础&#xff0c;涵盖了按钮、输入框、容器、显示组件等&#xff0c;适用于传统 Widget 开发&#xff08;基于 QWidget&#xff09;。以下是常用基本控件的分类总结&#xff1a;一、按钮类控件用于触发交互操作&#xff0c;如提交、取消、选择等。…

用Voe3做AI流量视频,条条10W+(附提示词+白嫖方法)

最近 AI 视频的风从大洋彼岸吹过来&#xff0c;Voe3 的技术升级&#xff0c;诞生了很多很有意思的玩法。 比如&#xff1a;AI ASMR 切水果解压视频&#xff0c;卡皮巴拉旅行博主、雪怪 AI Vlog&#xff0c;动物奥运会、第一人称视角穿越古战场直播。 这些视频的流量很好&…