如何使用chrome访问本地文件(--allow-access不起作用)

问题描述 投票:1回答:1

我正在为网页运行python脚本。 python脚本连接到localhost:5000。在一个HTML中我有一些我想加载的本地存储中的图像。

我已将文件设置为src到file:///path/to/file/some_image.jpg

但是我一直得到错误Not allowed to load local resource

我试图使用:"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --allow-file-access-from-files允许本地访问

但是我得到了同样的错误。我已经尝试重新启动计算机,chrome并从管理员运行所有内容但仍然没有运气。

如何使用localhost在chrome中运行本地文件?

python html google-chrome localhost
1个回答
0
投票

那你有没有检查过你是否有权访问这些文件?

也许你可以尝试使用selenium通过python控制chrome,下面是一个简单的python代码,你可以检查出来(将google.com替换为你的html文件)。

http://selenium-python.readthedocs.io/installation.html#introduction

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument("--allow-file-access-from-files")
driver = webdriver.Chrome("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", chrome_options=options)
driver.get("http://www.google.com")
© www.soinside.com 2019 - 2024. All rights reserved.