{ "cells": [ { "cell_type": "code", "execution_count": 10, "id": "09dde3c9-bd15-4cac-a8d7-b386e5fdcd88", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: virtualenv in /opt/conda/lib/python3.9/site-packages (20.8.1)\n", "Requirement already satisfied: platformdirs<3,>=2 in /opt/conda/lib/python3.9/site-packages (from virtualenv) (2.4.0)\n", "Requirement already satisfied: filelock<4,>=3.0.0 in /opt/conda/lib/python3.9/site-packages (from virtualenv) (3.2.0)\n", "Requirement already satisfied: distlib<1,>=0.3.1 in /opt/conda/lib/python3.9/site-packages (from virtualenv) (0.3.3)\n", "Requirement already satisfied: six<2,>=1.9.0 in /opt/conda/lib/python3.9/site-packages (from virtualenv) (1.16.0)\n", "Requirement already satisfied: backports.entry-points-selectable>=1.0.4 in /opt/conda/lib/python3.9/site-packages (from virtualenv) (1.1.0)\n", "created virtual environment CPython3.9.6.final.0-64 in 523ms\n", " creator CPython3Posix(dest=/home/jovyan/projects/jupyter/home/seleniumbase/project/env, clear=False, no_vcs_ignore=False, global=False)\n", " seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/jovyan/.local/share/virtualenv)\n", " added seed packages: pip==21.2.4, selenium==3.141.0, setuptools==58.1.0, urllib3==1.26.7, wheel==0.37.0\n", " activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator\n", "Requirement already satisfied: selenium in ./env/lib/python3.9/site-packages (3.141.0)\n", "Requirement already satisfied: urllib3 in ./env/lib/python3.9/site-packages (from selenium) (1.26.7)\n", "Archive: chromedriver_linux64.zip\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "File ‘chromedriver_linux64.zip’ already there; not retrieving.\n", "\n", "bash: line 10: cd: /home/jovyan/project: No such file or directory\n", "mv: cannot stat '/home/jovyan/test.py': No such file or directory\n", "python3: can't open file '/home/jovyan/projects/jupyter/home/seleniumbase/project/env/bin/test.py': [Errno 2] No such file or directory\n" ] }, { "ename": "CalledProcessError", "evalue": "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.", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mCalledProcessError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m/tmp/ipykernel_876/3478213483.py\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mget_ipython\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrun_cell_magic\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'script'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'bash'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'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'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;32m/opt/conda/lib/python3.9/site-packages/IPython/core/interactiveshell.py\u001b[0m in \u001b[0;36mrun_cell_magic\u001b[0;34m(self, magic_name, line, cell)\u001b[0m\n\u001b[1;32m 2401\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbuiltin_trap\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2402\u001b[0m \u001b[0margs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mmagic_arg_s\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcell\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2403\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2404\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2405\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/opt/conda/lib/python3.9/site-packages/decorator.py\u001b[0m in \u001b[0;36mfun\u001b[0;34m(*args, **kw)\u001b[0m\n\u001b[1;32m 230\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mkwsyntax\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 231\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkw\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfix\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkw\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msig\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 232\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mcaller\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfunc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mextras\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkw\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 233\u001b[0m \u001b[0mfun\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__name__\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__name__\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 234\u001b[0m \u001b[0mfun\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__doc__\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__doc__\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/opt/conda/lib/python3.9/site-packages/IPython/core/magic.py\u001b[0m in \u001b[0;36m\u001b[0;34m(f, *a, **k)\u001b[0m\n\u001b[1;32m 185\u001b[0m \u001b[0;31m# but it's overkill for just that one bit of state.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 186\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mmagic_deco\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marg\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 187\u001b[0;31m \u001b[0mcall\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mlambda\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 188\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 189\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mcallable\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marg\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/opt/conda/lib/python3.9/site-packages/IPython/core/magics/script.py\u001b[0m in \u001b[0;36mshebang\u001b[0;34m(self, line, cell)\u001b[0m\n\u001b[1;32m 243\u001b[0m \u001b[0msys\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstderr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mflush\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 244\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mraise_error\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreturncode\u001b[0m\u001b[0;34m!=\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 245\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mCalledProcessError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreturncode\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcell\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moutput\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mout\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstderr\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0merr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 246\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 247\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m_run_script\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mp\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcell\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mto_close\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mCalledProcessError\u001b[0m: 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." ] } ], "source": [ "%%script bash\n", "python -m pip install virtualenv\n", "mkdir -p project\n", "cd project\n", "virtualenv env\n", ". env/bin/activate\n", "python -m pip install selenium\n", "cd env/bin/\n", "wget -nc https://chromedriver.storage.googleapis.com/83.0.4103.39/chromedriver_linux64.zip\n", "unzip -u chromedriver_linux64.zip\n", "cd /home/jovyan/project\n", "mv /home/jovyan/test.py .\n", "python3 test.py" ] }, { "cell_type": "code", "execution_count": 11, "id": "56cf24b0-1066-4d73-a8e4-322203d0159f", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/bin/bash: chromium-browser: command not found\n" ] } ], "source": [ "!chromium-browser --version" ] }, { "cell_type": "code", "execution_count": 12, "id": "3d002e9c-64ae-49d4-9b7c-9fe899345d43", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ChromeDriver 83.0.4103.39 (ccbf011cb2d2b19b506d844400483861342c20cd-refs/branch-heads/4103@{#416})\n" ] } ], "source": [ "!./project/env/bin/chromedriver --version" ] }, { "cell_type": "code", "execution_count": 4, "id": "9416d20d-0755-4b25-a031-baf5440aafc6", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Writing test.py\n" ] } ], "source": [ "%%writefile test.py\n", "#from selenium import webdriver\n", "#driver = webdriver.Chrome()\n", "from selenium import webdriver\n", "from selenium.webdriver.chrome.options import Options\n", "\n", "chrome_options = Options()\n", "#chrome_options.add_argument('--no-sandbox')\n", "chrome_options.add_argument('--headless')\n", "#chrome_options.add_argument('--disable-dev-shm-usage')\n", "driver = webdriver.Chrome('/home/jovyan/project/env/bin/chromedriver',options=chrome_options)\n", "driver.get(\"https://sellercentral.amazon.com\")\n", "print(driver.page_source)" ] }, { "cell_type": "code", "execution_count": 9, "id": "407dd380-e5ac-4b51-98f8-a6613df88da9", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Collecting selenium\n", " Using cached selenium-3.141.0-py2.py3-none-any.whl (904 kB)\n", "Requirement already satisfied: urllib3 in /opt/conda/lib/python3.9/site-packages (from selenium) (1.26.7)\n", "Installing collected packages: selenium\n", "Successfully installed selenium-3.141.0\n", "Traceback (most recent call last):\n", " File \"/opt/conda/lib/python3.9/site-packages/selenium/webdriver/common/service.py\", line 72, in start\n", " self.process = subprocess.Popen(cmd, env=self.env,\n", " File \"/opt/conda/lib/python3.9/subprocess.py\", line 951, in __init__\n", " self._execute_child(args, executable, preexec_fn, close_fds,\n", " File \"/opt/conda/lib/python3.9/subprocess.py\", line 1821, in _execute_child\n", " raise child_exception_type(errno_num, err_msg, err_filename)\n", "FileNotFoundError: [Errno 2] No such file or directory: '/home/jovyan/project/env/bin/chromedriver'\n", "\n", "During handling of the above exception, another exception occurred:\n", "\n", "Traceback (most recent call last):\n", " File \"/home/jovyan/projects/jupyter/home/seleniumbase/test.py\", line 10, in \n", " driver = webdriver.Chrome('/home/jovyan/project/env/bin/chromedriver',options=chrome_options)\n", " File \"/opt/conda/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py\", line 73, in __init__\n", " self.service.start()\n", " File \"/opt/conda/lib/python3.9/site-packages/selenium/webdriver/common/service.py\", line 81, in start\n", " raise WebDriverException(\n", "selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home\n", "\n" ] } ], "source": [ "import sys\n", "!{sys.executable} -m pip install selenium\n", "\n", "!python3 test.py" ] }, { "cell_type": "code", "execution_count": null, "id": "5c0ccc3c-f932-4e4d-b190-b050fe678169", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.7" } }, "nbformat": 4, "nbformat_minor": 5 }