Add a ChatGPT example

This commit is contained in:
Michael Mintz 2025-01-28 20:50:55 -05:00
parent e86e07cea3
commit ed363ff8f3
1 changed files with 13 additions and 0 deletions

View File

@ -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:", ":"))