通過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
英文地址,請注明出處:http://en.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;動物奧運會、第一人稱視角穿越古戰場直播。 這些視頻的流量很好&…