Skip to content

Instantly share code, notes, and snippets.

@DanEdens
Created December 23, 2022 17:05
Show Gist options
  • Save DanEdens/b94615720b1f81f4e740ada2f174596a to your computer and use it in GitHub Desktop.
Save DanEdens/b94615720b1f81f4e740ada2f174596a to your computer and use it in GitHub Desktop.
python ask chatgpt with screenshot
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
# Start a new webdriver instance
driver = webdriver.Firefox()
# Navigate to the page with the text field
driver.get('http://www.example.com/chatgpt')
# Find the text field element on the page
text_field = driver.find_element_by_id('chatgpt-input')
# Enter the provided text into the text field
text_field.send_keys('Hello, world!')
# Submit the form containing the text field
text_field.send_keys(Keys.RETURN)
In this example, we are using the Firefox webdriver to navigate to a page with a text field on it, finding the text field element, entering the provided text into it, and then submitting the form containing the text field. This will submit the entered text to the chatgpt service.
You can replace the URL in the driver.get() call with the URL of the chatgpt service, and you can replace the text in the text_field.send_keys() call with the text that you want to submit to chatgpt.
from selenium import webdriver
# Start a new webdriver instance
driver = webdriver.Firefox()
# Navigate to the page with the results
driver.get('http://www.example.com/results')
# Wait for the results to be displayed on the page
driver.implicitly_wait(10)
# Take a screenshot of the page
driver.save_screenshot('results.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment