我想在pythonista中创建一个可以控制Web浏览器的程序。我知道Selenium是最好的,但是我已经在我的iOS iPhone上使用pythonista进行了尝试,但是我收到了错误。
这是代码:
from selenium import webdriver
browser = webdriver.Chrome()
browser.get('http://www.yahoo.com')
这是错误:
PermissionError: [Errno 1] Operation not permitted
Traceback (most recent call last):
File "/private/var/mobile/Containers/Shared/AppGroup/A2EBDF28-CB6C-4190-8199-7406AA3821A3/Pythonista3/Documents/selen.py", line 3, in <module>
browser = webdriver.Chrome()
File "/private/var/mobile/Containers/Shared/AppGroup/A2EBDF28-CB6C-4190-8199-7406AA3821A3/Pythonista3/Documents/site-packages-3/selenium/webdriver/chrome/webdriver.py", line 68, in __init__
self.service.start()
File "/private/var/mobile/Containers/Shared/AppGroup/A2EBDF28-CB6C-4190-8199-7406AA3821A3/Pythonista3/Documents/site-packages-3/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/var/containers/Bundle/Application/24DD2A57-320E-4E21-9BE2-7C3605830DE0/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/subprocess.py", line 708, in __init__
restore_signals, start_new_session)
File "/var/containers/Bundle/Application/24DD2A57-320E-4E21-9BE2-7C3605830DE0/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/subprocess.py", line 1261, in _execute_child
restore_signals, start_new_session, preexec_fn)
PermissionError: [Errno 1] Operation not permitted
答案 0 :(得分:1)
此错误消息......
PermissionError: [Errno 1] Operation not permitted
...表示 ChromeDriver 无法创建所需的新资源,例如初始化新的 WebDriver 和 Web客户端会话时, logfile 。
根据讨论 Pythonista
- Limitations due to iOS
以下是使用 Pythonista 时的一些限制:
/dev/null
和其他特殊文件。一个简单的例子如下:
>>> import subprocess
>>> subprocess.call(["ls", "-l"])
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/mobile/Containers/Bundle/Application/8C59C68D-71BF-4CBB-90F8-373A1752DEE1/Pythonista.app/pylib/subprocess.py", line 524, in call
return Popen(*popenargs, **kwargs).wait()
File "/private/var/mobile/Containers/Bundle/Application/8C59C68D-71BF-4CBB-90F8-373A1752DEE1/Pythonista.app/pylib/subprocess.py", line 711, in __init__
errread, errwrite)
File "/private/var/mobile/Containers/Bundle/Application/8C59C68D-71BF-4CBB-90F8-373A1752DEE1/Pythonista.app/pylib/subprocess.py", line 1205, in _execute_child
self.pid = os.fork()
OSError: [Errno 1] Operation not permitted
可能有以下两个问题:
当您调用以下代码行时:
browser = webdriver.Chrome()
ChromeDriver 尝试创建 / 修改 / 访问 scoped_directory 文件系统。例如,在 Windows OS :
上"chromedriverVersion": "2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73)",
"userDataDir": "C:\\Users\\username\\AppData\\Local\\Temp\\scoped_dir5188_12717"
可能 ChromeDriver 无法执行此任务/方法/功能。
再次调用以下代码行时:
browser = webdriver.Chrome()
根据selenium.webdriver.chrome.webdriver
ChromeDriver 尝试按照构造函数在文件系统中创建logfile
,如下所示:
class selenium.webdriver.chrome.webdriver.WebDriver(executable_path='chromedriver', port=0, options=None, service_args=None, desired_capabilities=None, service_log_path=None, chrome_options=None)
可能 ChromeDriver 无法执行此任务/方法/功能,
由于上述原因,您会看到错误:
PermissionError: [Errno 1] Operation not permitted
如果出现上述任何一种情况,解决方案是仅限制应用程序目录中访问 / 创建的资源