Skip to content

Commit

Permalink
Merge pull request #3338 from seleniumbase/cdp-mode-patch-20
Browse files Browse the repository at this point in the history
CDP Mode - Patch 20
  • Loading branch information
mdmintz authored Dec 13, 2024
2 parents 6e0c8c5 + b00f6cb commit c2d144e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
36 changes: 36 additions & 0 deletions examples/cdp_mode/raw_socialblade.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Bypass bot-detection to view SocialBlade ranks for YouTube"""
from seleniumbase import SB

with SB(uc=True, test=True, ad_block=True, pls="none") as sb:
url = "https://socialblade.com/"
sb.activate_cdp_mode(url)
sb.sleep(1.5)
sb.uc_gui_click_captcha()
sb.sleep(0.5)
channel_name = "michaelmintz"
sb.cdp.press_keys('input[name="query"]', channel_name)
sb.cdp.click('form[action*="/search"] button')
sb.sleep(2)
sb.cdp.click('a[title="%s"] h2' % channel_name)
sb.sleep(1.5)
sb.cdp.remove_elements("#lngtd-top-sticky")
sb.sleep(1.5)
name = sb.cdp.get_text("h1")
link = sb.cdp.get_attribute("#YouTubeUserTopInfoBlockTop h4 a", "href")
subscribers = sb.cdp.get_text("#youtube-stats-header-subs")
video_views = sb.cdp.get_text("#youtube-stats-header-views")
rankings = sb.cdp.get_text(
'#socialblade-user-content [style*="border-bottom"]'
).replace("\xa0", "").replace(" ", " ").replace(" ", " ")
print("********** SocialBlade Stats for %s: **********" % name)
print(">>> (Link: %s) <<<" % link)
print("* YouTube Subscribers: %s" % subscribers)
print("* YouTube Video Views: %s" % video_views)
print("********** SocialBlade Ranks: **********")
for row in rankings.split("\n"):
if len(row.strip()) > 8:
print("--> " + row.strip())
for i in range(17):
sb.cdp.scroll_down(6)
sb.sleep(0.1)
sb.sleep(2)
2 changes: 1 addition & 1 deletion seleniumbase/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# seleniumbase package
__version__ = "4.33.9"
__version__ = "4.33.10"
15 changes: 9 additions & 6 deletions seleniumbase/undetected/cdp_driver/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,15 @@ async def apply(self, js_function, return_by_value=True):
)
)
)
if result and result[0]:
if return_by_value:
return result[0].value
return result[0]
elif result[1]:
return result[1]
try:
if result and result[0]:
if return_by_value:
return result[0].value
return result[0]
elif result[1]:
return result[1]
except Exception:
return self

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

0 comments on commit c2d144e

Please sign in to comment.