Skip to content

Instantly share code, notes, and snippets.

@zmarffy
Last active August 30, 2023 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zmarffy/11eee870c73d6a25d49bacc06b24a8ab to your computer and use it in GitHub Desktop.
Save zmarffy/11eee870c73d6a25d49bacc06b24a8ab to your computer and use it in GitHub Desktop.
Generate a GitHub personal access token using Selenium (because why not)
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from os.path import devnull
options = Options()
options.headless = True
driver = None
username = "somehow get a username into here"
password = "somehow get a password into here"
driver = webdriver.Firefox(service_log_path=devnull, options=options)
try:
driver.get("https://github.com/settings/tokens")
driver.find_element_by_id("login_field").send_keys(username)
driver.find_element_by_id("password").send_keys(password)
driver.find_element_by_css_selector("[type='submit']").click()
driver.get("https://github.com/settings/tokens/new")
driver.find_element_by_id("oauth_access_description").send_keys("an_access_token")
driver.find_element_by_css_selector("[type='checkbox'][value='repo']").click()
driver.find_elements_by_css_selector("button[type='submit']")[-1].click()
print(driver.find_element_by_id("new-oauth-token").text) # or store it in a variable or something
finally:
driver.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment