当前位置: 首页 > news >正文

通过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.dtcms.com/a/331465.html

相关文章:

  • 【从零开始学习Redis】项目实战-黑马点评D1
  • Docker network网络管理入门教程
  • OpenCV 在图像上绘制二维图形的类cv::plot::Plot2d
  • 心灵笔记:沟通与协作
  • 搭建纯积分商城的关键注意事项
  • MySQL中的DML(二)
  • Spring基础面试题(三)
  • rtthread - ROMFS 的使用方式
  • 【自动驾驶】自动驾驶概述 ① ( 自动驾驶 与 无人驾驶 | 自动驾驶 相关岗位 及 技能需求 )
  • 网络安全应急响应
  • Java Stream API:让业务数据处理更优雅
  • 【120页PPT】人工智能与数字化转型的业财融合(附下载方式)
  • TDengine IDMP 基本功能(6. 无问智推)
  • Web攻防-业务逻辑篇APP隐私合规资源处理违规收集拒绝服务在线检测项目工具
  • 深度剖析!体育数据 API 及电竞数据 API 在体育电竞领域的核心地位
  • java动态代理机制I(初稿)
  • 职得AI简历-免费AI简历生成工具
  • C++ 排序指南
  • 7、C 语言数组进阶知识点总结
  • 解决SQL Server连接失败:Connection refused: connect
  • 力扣(LeetCode) ——225 用队列实现栈(C语言)
  • C++中的回调函数
  • C++中的内存管理(一)
  • BitDock——让你的Windows桌面变为Mac
  • 【ai写代码】lua-判断表是否被修改
  • Mysql基本使用语句(一)
  • [激光原理与应用-271]:理论 - 波动光学 - 电磁波谱,光是一种可视化的电磁波
  • 广义矩估计随机近似中1.2和2.1的差异
  • 获取iframe中canvas画面
  • 爬虫数据存储全攻略:从 Robots 协议到文件存储