You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A Python library to automate Tor Browser with Selenium.
4
+
A Python library to automate Tor Browser with Selenium WebDriver.
5
5
6
-
## Installation
6
+
## 📦 Installation
7
7
8
8
```
9
9
pip install tbselenium
10
10
```
11
11
12
12
Download `geckodriver` v0.31.0 from the [geckodriver releases page](https://github.com/mozilla/geckodriver/releases/) and add it to PATH.
13
13
14
-
## Basic usage
14
+
## 🚀 Usage
15
+
16
+
Download and extract [Tor Browser](https://www.torproject.org/projects/torbrowser.html.en), and pass its path when you initialize `TorBrowserDriver`.
17
+
18
+
15
19
### Using with system `tor`
16
20
17
21
`tor` needs to be installed (`apt install tor`) and running on port 9050.
@@ -23,8 +27,8 @@ with TorBrowserDriver("/path/to/tor-browser/") as driver:
23
27
```
24
28
25
29
### Using with `Stem`
26
-
First, make sure you have `Stem` installed (`pip install stem`).
27
-
The following will start a new `tor` process using `Stem`. It will not use the `tor` installed on your system.
30
+
You can use `Stem` to start a new tor process programmatically, and connect to it from `tor-browser-selenium`. Make sure you have `Stem` installed: `pip install stem`:
31
+
28
32
29
33
```python
30
34
import tbselenium.common as cm
@@ -39,55 +43,49 @@ with TorBrowserDriver(tbb_dir, tor_cfg=cm.USE_STEM) as driver:
39
43
tor_process.kill()
40
44
```
41
45
42
-
`tor-browser-selenium` does not download the Tor Browser for you.
43
-
You should [download](https://www.torproject.org/projects/torbrowser.html.en)
44
-
and extract, and pass its path when you initialize `TorBrowserDriver`.
45
46
46
-
47
-
48
-
## Examples
47
+
## 💡 Examples
49
48
Check the [examples](https://github.com/webfp/tor-browser-selenium/tree/master/examples) to discover different ways to use `tor-browser-selenium`
50
-
*[check_tpo.py](https://github.com/webfp/tor-browser-selenium/tree/master/examples/check_tpo.py): Visit check.torproject.org website and print the network status message
51
-
*[headless.py](https://github.com/webfp/tor-browser-selenium/tree/master/examples/headless.py): Headless visit and screenshot of check.torproject.org using XVFB
49
+
*[check_tpo.py](https://github.com/webfp/tor-browser-selenium/tree/master/examples/check_tpo.py): Visit the `check.torproject.org` website and print the network status message
50
+
*[headless.py](https://github.com/webfp/tor-browser-selenium/tree/master/examples/headless.py): Headless visit and screenshot of check.torproject.org using [PyVirtualDisplay](https://pypi.org/project/PyVirtualDisplay/)
52
51
*[onion_service.py](https://github.com/webfp/tor-browser-selenium/blob/main/examples/onion_service.py): Search using DuckDuckGo's Onion service
53
-
*[parallel.py](https://github.com/webfp/tor-browser-selenium/tree/master/examples/parallel.py): Visit check.torproject.org with 3 browsers running in parallel
52
+
*[parallel.py](https://github.com/webfp/tor-browser-selenium/tree/master/examples/parallel.py): Visit `check.torproject.org`` with 3 browsers running in parallel
54
53
*[screenshot.py](https://github.com/webfp/tor-browser-selenium/tree/master/examples/screenshot.py): Take a screenshot
55
-
*[stem_simple.py](https://github.com/webfp/tor-browser-selenium/tree/master/examples/stem_simple.py): Using Stem to start the Tor process
56
-
*[stem_adv.py](https://github.com/webfp/tor-browser-selenium/tree/master/examples/stem_adv.py): Using Stem with more advanced configuration
54
+
*[stem_simple.py](https://github.com/webfp/tor-browser-selenium/tree/master/examples/stem_simple.py): Use Stem to start a `tor` process
55
+
*[stem_adv.py](https://github.com/webfp/tor-browser-selenium/tree/master/examples/stem_adv.py): Use Stem to launch `tor` with more advanced configuration
57
56
58
57
59
58
60
-
## Test and development
59
+
## 🛠️ Test and development
61
60
62
-
Browse the [existing tests](https://github.com/webfp/tor-browser-selenium/tree/main/tbselenium/test) to find out about different ways you can use `tor-browser-selenium`.
61
+
*Browse the [existing tests](https://github.com/webfp/tor-browser-selenium/tree/main/tbselenium/test) to find out about different ways you can use `tor-browser-selenium`.
63
62
64
-
For development and testing first install the necessary Python packages:
63
+
* For development and testing first install the necessary Python packages:
64
+
`pip install -r requirements-dev.txt`
65
65
66
-
`pip install -r requirements-dev.txt`
66
+
* Install the `xvfb` package by running `apt-get install xvfb` or using your distro's package manager.
67
67
68
-
Install the `xvfb` package by running `apt-get install xvfb` or using your distro's package manager.
68
+
* Run the following to launch the tests:
69
69
70
-
Run the following to launch the tests:
70
+
`./run_tests.py /path/to/tor-browser/`
71
71
72
-
`./run_tests.py /path/to/tor-browser/`
73
-
74
-
By default, tests will be run using `Xvfb`, so the browser window will not be visible.
72
+
* By default, tests will be run using `Xvfb`, so the browser window will not be visible.
75
73
You may disable `Xvfb` by setting the `NO_XVFB` environment variable:
76
74
77
-
`export NO_XVFB=1`
75
+
`export NO_XVFB=1`
78
76
79
77
80
78
### Running individual tests
81
-
First, export the path to Tor Browser folder in the `TBB_PATH` environment variable.
79
+
*First, export the path to Tor Browser folder in the `TBB_PATH` environment variable.
82
80
83
81
`export TBB_PATH=/path/to/tbb/tor-browser/`
84
82
85
-
Then, use `py.test` to launch the tests you want, e.g.:
83
+
*Then, use `py.test` to launch the tests you want, e.g.:
[Tested](https://travis-ci.org/webfp/tor-browser-selenium) with the following Tor Browser versions on Ubuntu:
109
107
110
-
* 12.0.7
111
-
* 12.5a7
108
+
***Stable**: 12.0.7
109
+
***Alpha**: 12.5a7
112
110
113
111
If you need to use a different version of Tor Browser, [view the past test runs](https://travis-ci.org/webfp/tor-browser-selenium) to find out the compatible `selenium` and `geckodriver` versions.
114
112
115
-
## Troubleshooting
113
+
## 🔧 Troubleshooting
116
114
117
115
Solutions to potential issues:
118
116
@@ -128,7 +126,7 @@ Solutions to potential issues:
128
126
*`driver.get_cookies()` returns an empty list. This is due to Private Browsing Mode (PBM), which Selenium uses under the hood. See [#79](https://github.com/webfp/tor-browser-selenium/issues/79) for a possible solution.
129
127
* WebGL is not supported in the headless mode started with `headless=True` due to a Firefox bug ([#1375585](https://bugzilla.mozilla.org/show_bug.cgi?id=1375585)). To enable WebGL in a headless setting, use `pyvirtualdisplay` following the [headless.py](https://github.com/webfp/tor-browser-selenium/tree/master/examples/headless.py) example.
130
128
131
-
## Reference
129
+
## 📚 Reference
132
130
Please use the following reference if you use `tor-browser-selenium` in your academic publications.
133
131
134
132
```
@@ -141,5 +139,5 @@ Please use the following reference if you use `tor-browser-selenium` in your aca
141
139
}
142
140
```
143
141
144
-
## Credits
142
+
## 🙌 Credits
145
143
We greatly benefited from the [tor-browser-bundle-testsuite](https://gitlab.torproject.org/tpo/applications/tor-browser-bundle-testsuite) and [tor-browser-selenium](https://github.com/isislovecruft/tor-browser-selenium) projects.
0 commit comments