From: alex Date: Fri, 22 Apr 2022 18:18:54 +0000 (+0200) Subject: No longer recommend Selenium X-Git-Tag: 20240214-emacs~585 X-Git-Url: https://xn--ix-yja.es/gitweb/?a=commitdiff_plain;h=61031629931bd140a1eedc1e86d53799fa59b809;p=alex.git No longer recommend Selenium --- diff --git a/programming/python/scraping_with_selenium_on_docker.md b/programming/python/scraping_with_selenium_on_docker.md index f5dd1cd..ec22ee5 100644 --- a/programming/python/scraping_with_selenium_on_docker.md +++ b/programming/python/scraping_with_selenium_on_docker.md @@ -1,39 +1,5 @@ -Check that Docker is installed and your user can run Docker: +Don't use Selenium, use [Playwright](https://playwright.dev/python/): -``` -$ docker run --rm hello-world -``` - -Docker should print a success message, if not, review your Docker installation. - -Create a virtualenv and install `testcontainers` with `selenium` support: - -``` -$ python3 -m venv selenium_testcontainers_venv -$ . selenium_testcontainers_venv/bin/activate -$ pip install -U pip -$ pip install testcontainers[selenium] -``` - -Use in a Python terminal: - -``` -$ python ->>> from testcontainers import selenium ->>> from selenium.webdriver import DesiredCapabilities ->>> chrome = selenium.BrowserWebDriverContainer(DesiredCapabilities.CHROME) ->>> chrome.start() ->>> webdriver = chrome.get_driver() ->>> ... -``` - -Use in code: - -``` -from testcontainers import selenium -from selenium.webdriver import DesiredCapabilities - -with selenium.BrowserWebDriverContainer(DesiredCapabilities.CHROME) as chrome: - webdriver = chrome.get_driver() - ... -``` +* Playwright automatically sets up headless browsers. +* Provides convenient abstractions for locating elements in a page (mostly no XPath required. It can match "intelligently" using text). +* Has a handy UI tool that records your actions in a browser and writes equivalent *readable* Playwright code.