Open eunja511005 opened 1 month ago
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import pyperclip
from selenium.webdriver.common.keys import Keys
# Chrome WebDriver를 사용하여 Selenium 세션을 시작
driver = webdriver.Chrome()
login_url = "https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Feunja511005%2FAutoCoding%2Fissues"
main_url = "https://github.com/eunja511005/AutoCoding/issues"
try:
# 로그인
driver.get(login_url)
id_element = WebDriverWait(driver, 30).until(EC.visibility_of_element_located((By.CSS_SELECTOR,'#login_field')))
pyperclip.copy('eun@gmail.com')
id_element.send_keys(Keys.CONTROL+'v')
pyperclip.copy('sp########')
driver.find_element(By.ID, 'password').send_keys(Keys.CONTROL+'v')
driver.find_element(By.CSS_SELECTOR, '.btn.btn-primary.btn-block.js-sign-in-button').click()
# 메인 웹페이지 로드
driver.get(main_url) # 여기에 해당 웹페이지 URL을 입력
# id가 'global-create-menu-anchor'인 버튼 찾기
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.ID, 'global-create-menu-anchor')))
create_button = driver.find_element(By.ID, "global-create-menu-anchor")
create_button.click()
driver.save_screenshot('page_after_click.png')
# Selenium을 사용하여 모든 <a> 태그 수집
all_links_elements = driver.find_elements(By.ID, "global-create-menu-anchor")
# Selenium 요소를 BeautifulSoup에서 사용할 수 있는 HTML로 변환
html_content = ''.join([link.get_attribute('outerHTML') for link in all_links_elements])
# BeautifulSoup 객체 생성
soup = BeautifulSoup(html_content, 'html.parser')
# 이제 BeautifulSoup을 사용하여 원하는 작업 수행
all_buttons = soup.find_all("button", {"id": {"global-create-menu-anchor"}})
# 각 링크의 href 속성 출력
for botton in all_buttons:
print(botton.get('class'))
except Exception as e:
print(e)
finally:
# 작업 완료 후 드라이버 종료
driver.quit()
a 태그중 data-type이 toggle인 경우 클릭하는 셀레니움