Skip to content

Commit 6c65993

Browse files
committed
Add a new CDP Mode example
1 parent 025e647 commit 6c65993

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

examples/cdp_mode/raw_socialblade.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""Bypass bot-detection to view SocialBlade ranks for YouTube"""
2+
from seleniumbase import SB
3+
4+
with SB(uc=True, test=True, ad_block=True, pls="none") as sb:
5+
url = "https://socialblade.com/"
6+
sb.activate_cdp_mode(url)
7+
sb.sleep(1.5)
8+
sb.uc_gui_click_captcha()
9+
sb.sleep(0.5)
10+
channel_name = "michaelmintz"
11+
sb.cdp.press_keys('input[name="query"]', channel_name)
12+
sb.cdp.click('form[action*="/search"] button')
13+
sb.sleep(2)
14+
sb.cdp.click('a[title="%s"] h2' % channel_name)
15+
sb.sleep(1.5)
16+
sb.cdp.remove_elements("#lngtd-top-sticky")
17+
sb.sleep(1.5)
18+
name = sb.cdp.get_text("h1")
19+
link = sb.cdp.get_attribute("#YouTubeUserTopInfoBlockTop h4 a", "href")
20+
subscribers = sb.cdp.get_text("#youtube-stats-header-subs")
21+
video_views = sb.cdp.get_text("#youtube-stats-header-views")
22+
rankings = sb.cdp.get_text(
23+
'#socialblade-user-content [style*="border-bottom"]'
24+
).replace("\xa0", "").replace(" ", " ").replace(" ", " ")
25+
print("********** SocialBlade Stats for %s: **********" % name)
26+
print(">>> (Link: %s) <<<" % link)
27+
print("* YouTube Subscribers: %s" % subscribers)
28+
print("* YouTube Video Views: %s" % video_views)
29+
print("********** SocialBlade Ranks: **********")
30+
for row in rankings.split("\n"):
31+
if len(row.strip()) > 8:
32+
print("--> " + row.strip())
33+
for i in range(17):
34+
sb.cdp.scroll_down(6)
35+
sb.sleep(0.1)
36+
sb.sleep(2)

0 commit comments

Comments
 (0)