DEV Community

Tony Colston
Tony Colston

Posted on

2 1

gotta get down on Friday, scraping view counts from youtube

It is Friday. And you have to get down on Friday.

How many views does RB's video Friday have on Youtube right now?

You can do this with Selenium.

disclaimer this is clearly just for fun, some sites frown on being scraped... :)



ytlink="https://www.youtube.com/watch?v=kfVsfOSbJY0"

from selenium import webdriver
from selenium.webdriver.common.by import By

import time
driver = None

try:
    cpath = "e:\\projects\\headless\\chromedriver.exe"
    driver = webdriver.Chrome(cpath)
    driver.get(ytlink)
    # how do we fix this next statement?
    time.sleep(5)
    cs_selector = "#count > yt-view-count-renderer > span.view-count.style-scope.yt-view-count-renderer"
    e = driver.find_element(By.CSS_SELECTOR,cs_selector)
    time.sleep(3)
    txt_views = print(e.text)


finally:
    if driver is not None:
        driver.quit()
Enter fullscreen mode Exit fullscreen mode

Have a great weekend!!!

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay