This repository contains Selenium scripts that automate browsing YouTube to search for "computer donation program" and play a video from the "Kids Longhorn" channel.
youtube_selenium_script.py- Non-headless version (opens visible browser window)youtube_selenium_script_headless.py- Headless version (runs in background without GUI)
- Automatically navigates to YouTube
- Searches for "computer donation program"
- Identifies videos from the "Kids Longhorn" channel (@kidslonghorn3971)
- Plays the found video automatically
- Robust error handling and multiple selector strategies
- Cross-platform compatibility (Windows & Linux)
- Python 3.7 or higher
- Google Chrome browser (latest version recommended)
- ChromeDriver (matching your Chrome version)
- Download Python from python.org
- During installation, check "Add Python to PATH"
- Verify installation:
python --version pip --version
- Download from chrome.google.com
- Install with default settings
- Note your Chrome version:
Chrome Menu > Help > About Google Chrome
Option A: Automatic (Recommended)
pip install webdriver-managerOption B: Manual
- Download ChromeDriver from chromedriver.chromium.org
- Extract to a folder (e.g.,
C:\chromedriver\) - Add the folder to your system PATH:
- Right-click "This PC" β Properties β Advanced System Settings
- Click "Environment Variables"
- Under "System Variables", find "Path" and click "Edit"
- Click "New" and add your ChromeDriver folder path
- Click "OK" to save
pip install selenium webdriver-managergit clone https://github.com/blissfulProgrammer/selenium-youtube.git
cd selenium-youtube
python youtube_selenium_script.pysudo apt update && sudo apt upgrade -ysudo apt install python3 python3-pip -y
python3 --version
pip3 --version# Download and install Chrome
wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" | sudo tee /etc/apt/sources.list.d/google-chrome.list
sudo apt update
sudo apt install google-chrome-stable -y
# Verify installation
google-chrome --versionOption A: Automatic (Recommended)
pip3 install webdriver-managerOption B: Manual
# Find your Chrome version first
CHROME_VERSION=$(google-chrome --version | grep -oP '\d+\.\d+\.\d+')
echo "Chrome version: $CHROME_VERSION"
# Download matching ChromeDriver
wget -O chromedriver.zip "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${CHROME_VERSION%.*}/chromedriver_linux64.zip"
unzip chromedriver.zip
sudo mv chromedriver /usr/local/bin/
sudo chmod +x /usr/local/bin/chromedriver
rm chromedriver.zip
# Verify installation
chromedriver --versionpip3 install selenium webdriver-managergit clone https://github.com/blissfulProgrammer/selenium-youtube.git
cd selenium-youtube
python3 youtube_selenium_script.py# For CentOS/RHEL
sudo yum install python3 python3-pip -y
# For Fedora
sudo dnf install python3 python3-pip -y# Add Google Chrome repository
sudo tee /etc/yum.repos.d/google-chrome.repo <<EOF
[google-chrome]
name=google-chrome
baseurl=http://dl.google.com/linux/chrome/rpm/stable/x86_64
enabled=1
gpgcheck=1
gpgkey=https://dl.google.com/linux/linux_signing_key.pub
EOF
# Install Chrome
sudo yum install google-chrome-stable -y
# OR for Fedora: sudo dnf install google-chrome-stable -y# Windows
python youtube_selenium_script.py
# Linux
python3 youtube_selenium_script.py# Windows
python youtube_selenium_script_headless.py
# Linux
python3 youtube_selenium_script_headless.pyNavigating to YouTube...
Looking for search box...
Searching for 'computer donation program'...
Looking for videos from 'Kids Longhorn' channel...
Found 20 videos using selector: div#contents ytd-video-renderer
Checking if 'Kids Longhorn' exists in page source...
Found 'Kids Longhorn' in page source!
Found video from Kids Longhorn channel!
Video title: Computer Donation Program
Waiting for video to load...
Looking for play button...
Script completed successfully!
Video from Kids Longhorn channel should now be playing.
Solution: Ensure ChromeDriver is installed and in your PATH, or use webdriver-manager:
from webdriver_manager.chrome import ChromeDriverManager
service = Service(ChromeDriverManager().install())Solution: Install Google Chrome or specify the Chrome binary path:
chrome_options.binary_location = "/path/to/chrome" # Linux
chrome_options.binary_location = "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe" # WindowsSolution: Update both Chrome and ChromeDriver to matching versions:
# Check Chrome version
google-chrome --version # Linux
# OR check in Chrome: Menu > Help > About Google Chrome
# Download matching ChromeDriver from chromedriver.chromium.orgSolution: Make ChromeDriver executable:
sudo chmod +x /usr/local/bin/chromedriverSolution: Install virtual display:
sudo apt install xvfb -y
xvfb-run -a python3 youtube_selenium_script.py- The script searches for videos from "Kids Longhorn" channel (@kidslonghorn3971)
- If the video is not found, check if the channel has videos matching "computer donation program"
- The script will show available channels in search results for debugging
- Increase wait times in the script if your internet connection is slow
- Modify
time.sleep()values as needed
- These scripts are for educational purposes
- Respect YouTube's Terms of Service
- Don't use for automated spam or abuse
- Consider rate limiting for production use
Modify the search query in the script:
search_box.send_keys("your search term here")Update the channel detection logic:
has_kids_longhorn = ("Your Channel Name" in channel_name or
"yourchannel" in video_html.lower() or
"@yourchannelhandle" in video_html)Adjust timing for slower connections:
time.sleep(5) # Increase from 3 to 5 seconds- Fork the repository
- Create a feature branch
- Make your changes
- Test on both Windows and Linux
- Submit a pull request
This project is open source and available under the MIT License.
If you encounter issues:
- Check the troubleshooting section above
- Verify your Chrome and ChromeDriver versions match
- Ensure all dependencies are installed correctly
- Check your internet connection
- Review the console output for specific error messages
For additional help, please open an issue in the GitHub repository with:
- Your operating system and version
- Python version
- Chrome version
- ChromeDriver version
- Complete error message
- Steps to reproduce the issue