From 15a401eefa52961e1eaa574b0fbbfad96dae0040 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sat, 26 Oct 2024 16:01:21 -0400 Subject: [PATCH] Update the documentation --- examples/cdp_mode/ReadMe.md | 31 ++++++++++++++++--------------- help_docs/method_summary.md | 6 +++--- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/examples/cdp_mode/ReadMe.md b/examples/cdp_mode/ReadMe.md index 2c2315b5229..bf6ca1ea82b 100644 --- a/examples/cdp_mode/ReadMe.md +++ b/examples/cdp_mode/ReadMe.md @@ -2,7 +2,7 @@ ## [](https://github.com/seleniumbase/SeleniumBase/) CDP Mode 🐙 -🐙 SeleniumBase CDP Mode (Chrome Devtools Protocol Mode) is a special mode inside of SeleniumBase UC Mode that lets bots appear human while controlling the browser with the CDP-Driver. Although regular UC Mode can't perform WebDriver actions while the driver is disconnected from the browser, the CDP-Driver can still perform actions (while maintaining its cover). +🐙 SeleniumBase CDP Mode (Chrome Devtools Protocol Mode) is a special mode inside of SeleniumBase UC Mode that lets bots appear human while controlling the browser with the CDP-Driver. Although regular UC Mode can't perform WebDriver actions while the driver is disconnected from the browser, the CDP-Driver can still perform actions while maintaining its cover. (For Python 3.11 or newer!) 👤 UC Mode avoids bot-detection by first disconnecting WebDriver from the browser at strategic times, calling special PyAutoGUI methods to bypass CAPTCHAs (as needed), and finally reconnecting the driver afterwards so that WebDriver actions can be performed again. Although this approach works for bypassing simple CAPTCHAs, more flexibility is needed for bypassing bot-detection on websites with advanced protection. (That's where CDP Mode comes in.) @@ -74,15 +74,15 @@ from seleniumbase import SB with SB(uc=True, test=True, locale_code="en") as sb: url = "https://www.pokemon.com/us" sb.activate_cdp_mode(url) - sb.sleep(1.5) + sb.sleep(3) sb.cdp.click_if_visible("button#onetrust-reject-all-handler") - sb.sleep(0.5) + sb.sleep(1) sb.cdp.click('a[href="https://www.pokemon.com/us/pokedex/"]') sb.sleep(1) sb.cdp.click('b:contains("Show Advanced Search")') sb.sleep(1) sb.cdp.click('span[data-type="type"][data-value="electric"]') - sb.sleep(0.5) + sb.sleep(1) sb.cdp.click("a#advSearch") sb.sleep(1) sb.cdp.click('img[src*="img/pokedex/detail/025.png"]') @@ -130,13 +130,13 @@ from seleniumbase import SB with SB(uc=True, test=True, locale_code="en") as sb: url = "https://www.hyatt.com/" sb.activate_cdp_mode(url) - sb.sleep(1.5) + sb.sleep(2) sb.cdp.click_if_visible('button[aria-label="Close"]') - sb.sleep(0.5) + sb.sleep(1) sb.cdp.click('span:contains("Explore")') sb.sleep(1) sb.cdp.click('a:contains("Hotels & Resorts")') - sb.sleep(2.5) + sb.sleep(3) location = "Anaheim, CA, USA" sb.cdp.press_keys("input#searchbox", location) sb.sleep(1) @@ -145,7 +145,7 @@ with SB(uc=True, test=True, locale_code="en") as sb: sb.cdp.click('div.hotel-card-footer button') sb.sleep(1) sb.cdp.click('button[data-locator="find-hotels"]') - sb.sleep(4) + sb.sleep(5) hotel_names = sb.cdp.select_all( 'div[data-booking-status="BOOKABLE"] [class*="HotelCard_header"]' ) @@ -177,20 +177,20 @@ from seleniumbase import SB with SB(uc=True, test=True, locale_code="en") as sb: url = "https://www.bestwestern.com/en_US.html" sb.activate_cdp_mode(url) - sb.sleep(1.5) + sb.sleep(2.5) sb.cdp.click_if_visible("div.onetrust-close-btn-handler") - sb.sleep(0.5) + sb.sleep(1) sb.cdp.click("input#destination-input") - sb.sleep(1.5) + sb.sleep(2) location = "Palm Springs, CA, USA" sb.cdp.press_keys("input#destination-input", location) - sb.sleep(0.6) + sb.sleep(1) sb.cdp.click("ul#google-suggestions li") - sb.sleep(0.6) + sb.sleep(1) sb.cdp.click("button#btn-modify-stay-update") - sb.sleep(1.5) - sb.cdp.click("label#available-label") sb.sleep(4) + sb.cdp.click("label#available-label") + sb.sleep(2.5) print("Best Western Hotels in %s:" % location) summary_details = sb.cdp.get_text("#summary-details-column") dates = summary_details.split("ROOM")[0].split("DATES")[-1].strip() @@ -288,6 +288,7 @@ sb.cdp.get_document() sb.cdp.get_flattened_document() sb.cdp.get_element_attributes(selector) sb.cdp.get_element_html(selector) +sb.cdp.set_locale(locale) sb.cdp.set_attributes(selector, attribute, value) sb.cdp.internalize_links() sb.cdp.is_element_present(selector) diff --git a/help_docs/method_summary.md b/help_docs/method_summary.md index d79ba678b36..091f2bf71ef 100644 --- a/help_docs/method_summary.md +++ b/help_docs/method_summary.md @@ -349,7 +349,7 @@ self.save_page_source(name, folder=None) self.save_cookies(name="cookies.txt") -self.load_cookies(name="cookies.txt") +self.load_cookies(name="cookies.txt", expiry=False) self.delete_all_cookies() # Duplicates: self.clear_all_cookies() @@ -362,9 +362,9 @@ self.get_cookie(name) self.get_cookies() -self.add_cookie(cookie_dict) +self.add_cookie(cookie_dict, expiry=False) -self.add_cookies(cookies) +self.add_cookies(cookies, expiry=False) self.wait_for_ready_state_complete(timeout=None)