From ed363ff8f338c67e515f4254ce8d85a37d71a825 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Tue, 28 Jan 2025 20:50:55 -0500 Subject: [PATCH] Add a ChatGPT example --- examples/cdp_mode/raw_chatgpt.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 examples/cdp_mode/raw_chatgpt.py diff --git a/examples/cdp_mode/raw_chatgpt.py b/examples/cdp_mode/raw_chatgpt.py new file mode 100644 index 00000000..2d0bfb32 --- /dev/null +++ b/examples/cdp_mode/raw_chatgpt.py @@ -0,0 +1,13 @@ +from seleniumbase import SB + +with SB(uc=True, test=True, ad_block=True) as sb: + url = "https://chatgpt.com/" + sb.activate_cdp_mode(url) + query = "Compare Playwright to SeleniumBase in under 178 words" + sb.type("#prompt-textarea", query) + sb.click('button[data-testid="send-button"]') + print('Input for ChatGPT:\n"%s"' % query) + sb.sleep(12) + chat = sb.find_element('[data-message-author-role="assistant"] .markdown') + soup = sb.get_beautiful_soup(chat.get_html()).get_text("\n").strip() + print("Response from ChatGPT:\n%s" % soup.replace("\n:", ":"))