XPath
XPath
XML 문서의 특정 부분의 위치를 찾을 때 사용하는 언어
문서를 노드로 표현한 결과는 트리형태
요소나 속성의 위치를 지정하는 것이 가능
<html>
<body>
<h1> Hi </h1>
<div>
<span class="a"> Kor </span>
<span class="b"> Eng </span>
<span class="c"> EU </span>
</div>
</body)
</html>
html
|
body
|
---------------------------------------------------------
| |
h1 div
|
------------------------------------------------
| | |
span span span
XPATH : location path에 의해 표현
location path : 트리구조로 부터 특정 요소를 지정하기 위한 식
URL과 같이 / 문자를 이용해 요소를 연결
xpath : h1요소는 다음과 같이 지정
/html/body/h1
* 속성
- XPath 에서는 속성을 @ 로 표현
/html/body/div/span[@class='c'] 의 결과는 EU
- XPath는 // 을 이용하여 노드 패스를 생략할 수 있음
//는 descendant-or-self의 생략형으로 기준점이 되는 노드의 모든 자식 노드들의 집합
/html/body/div/span[@class='c'] == //span[@class='c']
span[@class='c']
- contains 지정하는 문자열이 포함되어 있는 요소를 얻을 수 있음
<src class="https://local_uri">
<src class="https://remotor_uri">
<src class="https://basic_URL">
//src[contains(@class,'uri')] 은 <src class="https://local_uri">
<src class="https://remotor_uri"> 을 모두 포함한다