Advertisement
AyanUpadhaya

Web Scraping with Selenium

Jun 4th, 2021
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. # Web scraping with selenium 101
  2. # Requirements: selenium module and a webdriver
  3. # For google chrome download chromedriver or for firefox download geckodriver
  4. # get the channel video page url
  5. # select a video and inspect and copy the css_selector
  6. # import selenium webdriver
  7. # Call the webdriver
  8. # Get the page by browser.get(url)
  9. # Open up the video by finding element by css selector and click()
  10.  
  11.  
  12. from selenium import webdriver
  13. from selenium.webdriver.common.keys import Keys
  14. import time
  15.  
  16. url='https://www.youtube.com/c/AGADMATOR/videos'
  17.  
  18. selector='ytd-grid-video-renderer.style-scope:nth-child(1) > div:nth-child(1) > ytd-thumbnail:nth-child(1) > a:nth-child(1)'
  19.  
  20. browser=webdriver.Firefox(executable_path='driver/geckodriver', timeout=10)
  21.  
  22. browser.get(url)
  23.  
  24. time.sleep(2)
  25.  
  26. browser.find_element_by_css_selector(selector).click()
  27.  
  28.  
  29.  
  30.  
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement