Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Web scraping with selenium 101
- # Requirements: selenium module and a webdriver
- # For google chrome download chromedriver or for firefox download geckodriver
- # get the channel video page url
- # select a video and inspect and copy the css_selector
- # import selenium webdriver
- # Call the webdriver
- # Get the page by browser.get(url)
- # Open up the video by finding element by css selector and click()
- from selenium import webdriver
- from selenium.webdriver.common.keys import Keys
- import time
- url='https://www.youtube.com/c/AGADMATOR/videos'
- selector='ytd-grid-video-renderer.style-scope:nth-child(1) > div:nth-child(1) > ytd-thumbnail:nth-child(1) > a:nth-child(1)'
- browser=webdriver.Firefox(executable_path='driver/geckodriver', timeout=10)
- browser.get(url)
- time.sleep(2)
- browser.find_element_by_css_selector(selector).click()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement