【发布时间】:2021-10-27 02:50:43
【问题描述】:
我可以在我的本地 python IDE 上运行 Selinium webdriver 来抓取网络数据,但我想在在线 python IDE 上实现它,例如 Jupyuter lab online 或 Google Colab,但是 chromedriver.exe 路径导致了一个问题在在线工具上,代码没有执行。我在 Jupyter lab online 和 google colab 上有以下代码:
import os
import sys
os.path.dirname(sys.executable)
from selenium import webdriver
browser = webdriver.Chrome(executable_path = '/home/jovyan/demo/chromedriver.exe' )
browser.get('https://www.youtube.com/')
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-19-5510b62cb210> in <module>
1 from selenium import webdriver
----> 2 browser = webdriver.Chrome(executable_path = '/home/jovyan/demo/chromedriver.exe' )
3
4 browser.get('https://www.youtube.com/' class="ansi-blue-fg">)
/srv/conda/envs/notebook/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py in __init__(self, executable_path, port, options, service_args, desired_capabilities, service_log_path, chrome_options, keep_alive)
71 service_args=service_args,
72 log_path=service_log_path)
---> 73 self.service.start()
74
75 try:
/srv/conda/envs/notebook/lib/python3.7/site-packages/selenium/webdriver/common/service.py in start(self)
74 stdout=self.log_file,
75 stderr=self.log_file,
---> 76 stdin=PIPE)
77 except TypeError:
78 raise
/srv/conda/envs/notebook/lib/python3.7/subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
798 c2pread, c2pwrite,
799 errread, errwrite,
--> 800 restore_signals, start_new_session)
801 except:
802 # Cleanup if the child failed starting.
/srv/conda/envs/notebook/lib/python3.7/subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)
1549 if errno_num == errno.ENOENT:
1550 err_msg += ': ' + repr(err_filename)
-> 1551 raise child_exception_type(errno_num, err_msg, err_filename)
1552 raise child_exception_type(err_msg)
1553
OSError: [Errno 8] Exec format error: '/home/jovyan/demo/chromedriver.exe'
如果您有解决此问题的任何解决方案或任何其他 python 平台,请告诉我,因为我的项目的进一步部分取决于此 webdriver。
【问题讨论】:
标签: python selenium web-scraping webdriver google-colaboratory