You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
15 KiB
15 KiB
<html>
<head>
</head>
</html>
In [10]:
%%script bash
python -m pip install virtualenv
mkdir -p project
cd project
virtualenv env
. env/bin/activate
python -m pip install selenium
cd env/bin/
wget -nc https://chromedriver.storage.googleapis.com/83.0.4103.39/chromedriver_linux64.zip
unzip -u chromedriver_linux64.zip
cd /home/jovyan/project
mv /home/jovyan/test.py .
python3 test.py
Requirement already satisfied: virtualenv in /opt/conda/lib/python3.9/site-packages (20.8.1)
Requirement already satisfied: platformdirs<3,>=2 in /opt/conda/lib/python3.9/site-packages (from virtualenv) (2.4.0)
Requirement already satisfied: filelock<4,>=3.0.0 in /opt/conda/lib/python3.9/site-packages (from virtualenv) (3.2.0)
Requirement already satisfied: distlib<1,>=0.3.1 in /opt/conda/lib/python3.9/site-packages (from virtualenv) (0.3.3)
Requirement already satisfied: six<2,>=1.9.0 in /opt/conda/lib/python3.9/site-packages (from virtualenv) (1.16.0)
Requirement already satisfied: backports.entry-points-selectable>=1.0.4 in /opt/conda/lib/python3.9/site-packages (from virtualenv) (1.1.0)
created virtual environment CPython3.9.6.final.0-64 in 523ms
creator CPython3Posix(dest=/home/jovyan/projects/jupyter/home/seleniumbase/project/env, clear=False, no_vcs_ignore=False, global=False)
seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/jovyan/.local/share/virtualenv)
added seed packages: pip==21.2.4, selenium==3.141.0, setuptools==58.1.0, urllib3==1.26.7, wheel==0.37.0
activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
Requirement already satisfied: selenium in ./env/lib/python3.9/site-packages (3.141.0)
Requirement already satisfied: urllib3 in ./env/lib/python3.9/site-packages (from selenium) (1.26.7)
Archive: chromedriver_linux64.zip
File ‘chromedriver_linux64.zip’ already there; not retrieving. bash: line 10: cd: /home/jovyan/project: No such file or directory mv: cannot stat '/home/jovyan/test.py': No such file or directory python3: can't open file '/home/jovyan/projects/jupyter/home/seleniumbase/project/env/bin/test.py': [Errno 2] No such file or directory
--------------------------------------------------------------------------- CalledProcessError Traceback (most recent call last) /tmp/ipykernel_876/3478213483.py in <module> ----> 1 get_ipython().run_cell_magic('script', 'bash', 'python -m pip install virtualenv\nmkdir -p project\ncd project\nvirtualenv env\n. env/bin/activate\npython -m pip install selenium\ncd env/bin/\nwget -nc https://chromedriver.storage.googleapis.com/83.0.4103.39/chromedriver_linux64.zip\nunzip -u chromedriver_linux64.zip\ncd /home/jovyan/project\nmv /home/jovyan/test.py .\npython3 test.py\n') /opt/conda/lib/python3.9/site-packages/IPython/core/interactiveshell.py in run_cell_magic(self, magic_name, line, cell) 2401 with self.builtin_trap: 2402 args = (magic_arg_s, cell) -> 2403 result = fn(*args, **kwargs) 2404 return result 2405 /opt/conda/lib/python3.9/site-packages/decorator.py in fun(*args, **kw) 230 if not kwsyntax: 231 args, kw = fix(args, kw, sig) --> 232 return caller(func, *(extras + args), **kw) 233 fun.__name__ = func.__name__ 234 fun.__doc__ = func.__doc__ /opt/conda/lib/python3.9/site-packages/IPython/core/magic.py in <lambda>(f, *a, **k) 185 # but it's overkill for just that one bit of state. 186 def magic_deco(arg): --> 187 call = lambda f, *a, **k: f(*a, **k) 188 189 if callable(arg): /opt/conda/lib/python3.9/site-packages/IPython/core/magics/script.py in shebang(self, line, cell) 243 sys.stderr.flush() 244 if args.raise_error and p.returncode!=0: --> 245 raise CalledProcessError(p.returncode, cell, output=out, stderr=err) 246 247 def _run_script(self, p, cell, to_close): CalledProcessError: Command 'b'python -m pip install virtualenv\nmkdir -p project\ncd project\nvirtualenv env\n. env/bin/activate\npython -m pip install selenium\ncd env/bin/\nwget -nc https://chromedriver.storage.googleapis.com/83.0.4103.39/chromedriver_linux64.zip\nunzip -u chromedriver_linux64.zip\ncd /home/jovyan/project\nmv /home/jovyan/test.py .\npython3 test.py\n'' returned non-zero exit status 2.
In [11]:
!chromium-browser --version
/bin/bash: chromium-browser: command not found
In [12]:
!./project/env/bin/chromedriver --version
ChromeDriver 83.0.4103.39 (ccbf011cb2d2b19b506d844400483861342c20cd-refs/branch-heads/4103@{#416})
In [4]:
%%writefile test.py
#from selenium import webdriver
#driver = webdriver.Chrome()
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
#chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--headless')
#chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome('/home/jovyan/project/env/bin/chromedriver',options=chrome_options)
driver.get("https://sellercentral.amazon.com")
print(driver.page_source)
Writing test.py
In [9]:
import sys
!{sys.executable} -m pip install selenium
!python3 test.py
Collecting selenium
Using cached selenium-3.141.0-py2.py3-none-any.whl (904 kB)
Requirement already satisfied: urllib3 in /opt/conda/lib/python3.9/site-packages (from selenium) (1.26.7)
Installing collected packages: selenium
Successfully installed selenium-3.141.0
Traceback (most recent call last):
File "/opt/conda/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "/opt/conda/lib/python3.9/subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/opt/conda/lib/python3.9/subprocess.py", line 1821, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/home/jovyan/project/env/bin/chromedriver'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/jovyan/projects/jupyter/home/seleniumbase/test.py", line 10, in <module>
driver = webdriver.Chrome('/home/jovyan/project/env/bin/chromedriver',options=chrome_options)
File "/opt/conda/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/opt/conda/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
In [ ]: