我用的是chrome 势头 扩展来定制我的浏览器新标签,并想写一个python脚本来获得它的每日仪表盘壁纸。
现在,我知道我可以通过网址到达所需的页面。
chrome-extension://laookkfknpbbblfpciffpaejjkokdgca/dashboard.html
然而,当我试图调用 urllib.request.urlopen
使用这个url,会出现以下错误。
urllib.error.URLError: <urlopen error unknown url type: chrome-extension>
是否可以包含自定义协议,以打开由 urllib
?
或者说有其他的方式来获取页面html结果?
如果文件存在于本地,而不是在网络上,那么使用urllib不会对你有什么好处,因为它不是一个URL。
使用 webbrowser lib 来代替,并提供一个文件的路径。
def auto_open():
"""
This method takes the absolute path to the html file and opens it directly in the browser.
"""
html_page = 'path/to/your/file'
# open in a new tab.
new = 2
webbrowser.open(html_page, new=new)