Flet 打包APK 成功但是,引用requests 之后异常 #2835
Unanswered
ChinaGodzilla
asked this question in
Q&A
Replies: 3 comments 2 replies
-
There are errors and deficiencies in the codes. Additionally, with the "flet build apk" command, the .apk file was created for me without any errors. Edited codes: import flet as ft
import requests
from bs4 import BeautifulSoup
Url_list = []
def Get_news():
global Url_list
Count = 0
Web_text = requests.get('https://news.china.com/domestic/?x4fc.html')
#print(Web_text.text)
soup = BeautifulSoup(Web_text.content.decode('utf8'), 'html.parser')
# 查找所有的标签
news_links = soup.find_all('a')
# 遍历每个<a>标签,输出链接和文本内容
for link in news_links:
Count += 1
href_value = link.get('href')
news_text = link.text
#print(f"Link: {href_value}, Text: {news_text}")
if Count > 40:
Url_list.append(news_text)
def main(page: ft.Page):
global Url_list
page.title = "疼殉新闻"
page.vertical_alignment = ft.MainAxisAlignment.CENTER
page.appbar = ft.AppBar(title=ft.Text('疼殉新闻'),center_title=True,color='white',bgcolor=ft.colors.BLUE)
page.navigation_bar = ft.NavigationBar(
destinations=[
ft.NavigationDestination(icon=ft.icons.HOME, label="首页"),
ft.NavigationDestination(icon=ft.icons.NAVIGATION, label="热点"),
ft.NavigationDestination(
icon=ft.icons.ACCOUNT_BOX,
selected_icon=ft.icons.BOOKMARK,
label="我的",
),
])
lv = ft.ListView(expand=True, spacing=10)
page.add(lv)
Get_news()
for i in Url_list:
lv.controls.append(ft.Text(str(i)))
page.update()
ft.app(main) |
Beta Was this translation helpful? Give feedback.
0 replies
-
@burhansvural thanks |
Beta Was this translation helpful? Give feedback.
1 reply
-
The final check was that the requirements.txt file did not fill in the dependencies, thank you. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I wrote a routine that did not include the requests package and packaged the APK so that it could run normally on Android. When I referenced the requests library and packaged the APK, an error was reported as shown below.
python code:
`import time
import flet as ft
import requests
from bs4 import BeautifulSoup
Url_list = []
def Get_news():
Count = 0
Web_text = requests.get('https://news.china.com/domestic/?x4fc.html')
#print(Web_text.text)
soup = BeautifulSoup(Web_text.content.decode('utf8'), 'html.parser')
# 查找所有的标签
news_links = soup.find_all('a')
def main(page: ft.Page):
page.title = "疼殉新闻"
page.vertical_alignment = ft.MainAxisAlignment.CENTER
page.appbar = ft.AppBar(title=ft.Text('疼殉新闻'),center_title=True,color='white',bgcolor=ft.colors.BLUE)
page.navigation_bar = ft.NavigationBar(
destinations=[
ft.NavigationDestination(icon=ft.icons.HOME, label="首页"),
ft.NavigationDestination(icon=ft.icons.NAVIGATION, label="热点"),
ft.NavigationDestination(
icon=ft.icons.ACCOUNT_BOX,
selected_icon=ft.icons.BOOKMARK,
label="我的",
),
]
)
ft.app(main)`
Packaging command
flet build apk --verbose
Beta Was this translation helpful? Give feedback.
All reactions