You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

iOS端Pythonista使用Selenium遇PermissionError权限问题求助

Fixing PermissionError with Selenium in Pythonista (iOS)

Hey there! That permission error you're hitting isn't a bug in your code—it's a core restriction of iOS's app sandbox. Let me break down why this happens and share some workable alternatives.

Why the Error Occurs

Selenium's webdriver.Chrome() tries to launch the ChromeDriver executable as a separate process. But on iOS, apps like Pythonista run in a sandboxed environment—they can't spawn external processes or access system-level executables. That's exactly why you're seeing PermissionError: [Errno 1] Operation not permitted.

Your original code for reference:

from selenium import webdriver
browser = webdriver.Chrome()
browser.get('http://www.yahoo.com')

And the full error trace:

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

Workable Alternatives for Pythonista on iOS

1. Use Pythonista's Built-in webview Module

Pythonista comes with a native webview module that lets you control a web browser directly within the app—no external drivers needed. Here's a simple example that replicates your original goal:

import ui
import webview

def load_yahoo():
    # Create a web view instance
    wv = webview.WebView()
    # Load the target URL
    wv.load_url('http://www.yahoo.com')
    # Wrap the web view in a UI window and display it
    view = ui.View()
    view.add_subview(wv)
    view.present('fullscreen')

if __name__ == '__main__':
    load_yahoo()

You can also interact with the page using wv.evaluate_javascript() to run custom JavaScript, which covers most interactive use cases you'd need from Selenium.

2. Static Content Scraping with requests + BeautifulSoup

If you only need to fetch and parse static web content (no interactive actions), skip the browser entirely. Use requests to grab the page source and BeautifulSoup to parse it:

import requests
from bs4 import BeautifulSoup

response = requests.get('http://www.yahoo.com')
soup = BeautifulSoup(response.text, 'html.parser')
# Example: Print all visible link texts on the page
for link in soup.find_all('a'):
    print(link.get_text(strip=True))

Key Takeaway

Selenium's traditional webdriver approach won't work on iOS due to sandbox restrictions. Stick to Pythonista's native tools like webview for interactive browsing, or use scraping libraries for static content needs.

内容的提问来源于stack exchange,提问作者Lemonds

火山引擎 最新活动