aboutsummaryrefslogtreecommitdiff
path: root/programming/python/scraping_with_selenium_on_docker.md
blob: f5dd1cdd0165039042ed80f3110a567262385d68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Check that Docker is installed and your user can run Docker:

```
$ 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()
    ...
```