Skip to content

CDP Mode - Patch 20 #3338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading