Skip to content

Commit c2d144e

Browse files
authored
Merge pull request #3338 from seleniumbase/cdp-mode-patch-20
CDP Mode - Patch 20
2 parents 6e0c8c5 + b00f6cb commit c2d144e

File tree

3 files changed

+46
-7
lines changed

3 files changed

+46
-7
lines changed

examples/cdp_mode/raw_socialblade.py

+36
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)

seleniumbase/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "4.33.9"
2+
__version__ = "4.33.10"

seleniumbase/undetected/cdp_driver/element.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -438,12 +438,15 @@ async def apply(self, js_function, return_by_value=True):
438438
)
439439
)
440440
)
441-
if result and result[0]:
442-
if return_by_value:
443-
return result[0].value
444-
return result[0]
445-
elif result[1]:
446-
return result[1]
441+
try:
442+
if result and result[0]:
443+
if return_by_value:
444+
return result[0].value
445+
return result[0]
446+
elif result[1]:
447+
return result[1]
448+
except Exception:
449+
return self
447450

448451
async def get_position_async(self, abs=False) -> Position:
449452
if not self.parent or not self.object_id:

0 commit comments

Comments
 (0)