在手机上使用Python打开网页,你可以使用以下方法:
使用系统命令
import os
os.system('open https://www.baidu.com') 适用于iOS和Android系统
使用webbrowser包
import webbrowser
url = 'https://www.baidu.com'
webbrowser.open(url, new=0, autoraise=True) 适用于iOS和Android系统
使用selenium工具(适用于Android系统,需要安装ChromeDriver):
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from time import sleep
chrome_options = Options()
chrome_options.add_argument("--headless") 无头模式
service = Service('/path/to/chromedriver') 替换为你的chromedriver路径
driver = webdriver.Chrome(service=service, options=chrome_options)
url = 'https://www.baidu.com'
driver.get(url)
sleep(5) 延迟5秒
driver.quit() 关闭浏览器
请确保你已经安装了相应的浏览器驱动程序,并且根据你的设备和需求选择合适的方法。