|
| 1 | +# Modern Web Automation With Python and Selenium |
| 2 | + |
| 3 | +This repository contains the module `bandcamp`, which is the sample app built in the Real Python tutorial [Modern Web Automation With Python and Selenium](https://realpython.com/modern-web-automation-with-python-and-selenium/). |
| 4 | + |
| 5 | +## Installation and Setup |
| 6 | + |
| 7 | +Create and activate a [Python virtual environment](https://realpython.com/python-virtual-environments-a-primer/). |
| 8 | + |
| 9 | +Then, install the requirements: |
| 10 | + |
| 11 | +```sh |
| 12 | +(venv) $ python -m pip install -r requirements.txt |
| 13 | +``` |
| 14 | + |
| 15 | +The only direct dependency for this project is [Selenium](https://selenium-python.readthedocs.io/). You should use a Python version of at least 3.10, which is necessary to support [structural pattern matching](https://realpython.com/structural-pattern-matching/). |
| 16 | + |
| 17 | +You'll need a [Firefox Selenium driver](https://selenium-python.readthedocs.io/installation.html#drivers) called `geckodriver` to run the project as-is. Make sure to [download and install](https://github.com/mozilla/geckodriver/releases) it before running the project. |
| 18 | + |
| 19 | +## Run the Bandcamp Discover Player |
| 20 | + |
| 21 | +To run the music player, install the package, then use the entry-point command from your command line: |
| 22 | + |
| 23 | +```sh |
| 24 | +(venv) $ python -m pip install . |
| 25 | +(venv) $ bandcamp-player |
| 26 | +``` |
| 27 | + |
| 28 | +You'll see a text-based user interface that allows you to interact with the music player: |
| 29 | + |
| 30 | +``` |
| 31 | +Type: play [<track_number>] | pause | tracks | more | exit |
| 32 | +> |
| 33 | +``` |
| 34 | + |
| 35 | +Type one of the available commands to interact with Bandcamp's Discover section through your headless browser. Listen to songs with `play`, pause the current song with `pause`, and restart it with `play`. List available tracks with `tracks`, and load more songs using `more`. You can exit the music player by typing `exit`. |
| 36 | + |
| 37 | +## Troubleshooting |
| 38 | + |
| 39 | +If the music player seems to hang when you run the script, confirm whether you've correctly set up your WebDriver based on the following points. |
| 40 | + |
| 41 | +### Version Compatibility |
| 42 | + |
| 43 | +Confirm that your browser and corresponding WebDriver are in sync. If you followed the previous suggestion, then you should be using Firefox and geckodriver. If that doesn't work for some reason, then you may need to switch your browser _and_ WebDriver. |
| 44 | + |
| 45 | +For example, if you're using Chrome, then you need to install ChromeDriver and it must match your Chrome version. Otherwise, you may run into errors like `SessionNotCreatedException`. |
| 46 | +For more details, refer to the official [ChromeDriver documentation](https://sites.google.com/chromium.org/driver/) or [geckodriver releases](https://github.com/mozilla/geckodriver/releases). |
| 47 | + |
| 48 | +### Driver Installation and Path Issues |
| 49 | + |
| 50 | +Once you've confirmed that your browser and driver match, make sure that the WebDriver executable is properly installed: |
| 51 | + |
| 52 | +- **Path Configuration:** The driver must be in your system's PATH, or you need to specify its full path in your code. |
| 53 | +- **Permissions:** Ensure the driver file has the necessary execution permissions. |
| 54 | + |
| 55 | +If you're still running into issues executing the script, then consult the [Selenium Documentation](https://www.selenium.dev/documentation/) for additional troubleshooting tips or leave a comment in the tutorial. |
| 56 | + |
| 57 | +## About the Authors |
| 58 | + |
| 59 | +Martin Breuss - Email: martin@realpython.com |
| 60 | +Bartosz Zaczyński - Email: bartosz@realpython.com |
| 61 | + |
| 62 | +## License |
| 63 | + |
| 64 | +Distributed under the MIT license. |
0 commit comments