Meta Data¶
구조 예시 (아래) : 개발자툴(F12)로 확인 가능. 마우스 우클릭 -> 검사 (권장)
div#id_name
div:no_attribute
목표 : Attribute가 없는 div의 text를 출력
In [1]:
import selenium
selenium.__version__
Out[1]:
'4.15.2'
Practice¶
In [2]:
from selenium import webdriver
from selenium.webdriver.edge.service import Service
from selenium.webdriver.edge.options import Options
from selenium.webdriver.common.by import By
In [3]:
driver = 'msedgedriver.exe'
options = Options()
service = Service(driver)
browser = webdriver.Edge(service=service, options=options)
browser.get('http://127.0.0.1:5500/example.html')
browser.implicitly_wait(2)
specific_element = browser.find_element(By.ID, 'id_name')
next_element = specific_element.find_element(By.XPATH, 'following-sibling::*[1]')
# by XPath, following-sibling 키워드로 같은 계층 elements :: 전체(*) 중 첫[1] element
print(next_element.text)
browser.quit()
div:no_attribute
728x90
'개발' 카테고리의 다른 글
Next.js Introduction (0) | 2024.04.20 |
---|---|
GPT기반 카카오톡 AI챗봇 해몽해드림 개발기 1(미완성) (1) | 2024.02.10 |
NoMachine 이용기 : 원격 데스크톱, 외부 연결 (2) | 2023.09.05 |
파이썬 개발자의 플러터 개발환경셋업 (MacOS, VSCode) (0) | 2023.06.26 |
라즈베리파이 VNC 'Cannot currently show the desktop' 해결 (0) | 2023.05.12 |