有没有办法让selenium不弹出?
我使用的是windows和python 3.8。
我尝试过使用";重影驱动器";但由于某种原因,它不起作用。
以下是我使用硒的用途:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from getpass import getpass
import time
import os
import password_for_github
#C:UsersnoDownloadschromedriver_winchromedriver.exe chrome driver
rep_name = str(input("rep name: "))
descrepition = str(input("rep description: "))
username = 'lemon4life2006@gmail.com'
password = password_for_github.password_HELLO
password1 = password_for_github.password_HELLO
if password == password1:
driver = webdriver.Chrome('C:\UsersAnasDownloadschromedriver_winchromedriver.exe')
driver.get('https://github.com/login')
time.sleep(1)
username_login = driver.find_element_by_id("login_field")
username_login.send_keys(username)
time.sleep(0.001)
password_login = driver.find_element_by_id("password")
password_login.send_keys(password)
time.sleep(0.001)
login_button = driver.find_element_by_xpath('//*[@id="login"]/form/div[4]/input[9]')
login_button.submit()
time.sleep(0.0001)
driver.get("https://github.com/new")
new_projectname = driver.find_element_by_id("repository_name")
new_projectname.send_keys(str(rep_name))
project_description = driver.find_element_by_xpath('//*[@id="repository_description"]')
project_description.send_keys(descrepition)
create_rep = driver.find_element_by_xpath('//*[@id="new_repository"]/div[4]/button')
create_rep.submit()
driver.quit()
elif password != password1:
print("wrong password try again (restart) ")
我想你正在寻找无头Chrome
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('headless')
path = 'C:\UsersAnasDownloadschromedriver_winchromedriver.exe'
driver = webdriver.Chrome(path, options=options)