python 打开网页、封装自己的浏览器
selenium
下载浏览器和浏览器驱动
功能全面,就是不能无边框
pip install selenium
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
# 浏览器启动参数
chrome_options = Options()
# 转 app
command = "--app=http://www.baidu.com"
chrome_options.add_argument(command)
# 允许http访问网络摄像头、麦克风
chrome_options.add_argument('--use-fake-ui-for-media-stream')
# 忽略证书错误
chrome_options.add_argument('--ignore-certificate-errors')
# 允许运行不安全的内容
chrome_options.add_argument('--allow-running-insecure-content')
path = r'C:\Users\xiahuadong\Downloads\chromedriver_win32\chromedriver.exe'
driver = webdriver.Chrome(
executable_path=path,
chrome_options=chrome_options
) # 获取chrome浏览器的驱动,并启动Chrome浏览器
# 窗口大小
# driver.set_window_size(500, 500)
# 窗口位置
# driver.set_window_position(500, 500)
# driver.get('https://www.baidu.com') # 打开百度
wxPython
不是chrome的内核,很多功能没有。
pip install wxPython
import wx
from wx.html2 import WebView
class MyHtmlFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, -1, title, size=(1024, 768))
web_view = WebView.New(self)
web_view.LoadURL("https://baidu.com/")
app = wx.App()
frm = MyHtmlFrame(None, "Browser")
frm.Show()
app.MainLoop()
import wx
import wx.html2
class MyBrowser(wx.Dialog):
def __init__(self, *args, **kwds)