xpath로 구문 분석하려고하는 다음 웹 페이지가 있습니다.Xpath로 HTML 구문 분석하기
첫 번째 테이블의 경우 xpath //*[@id="eForm"]/table[1]
이 잘 작동하고 두 번째 테이블의 경우 xpath //*[@id="eForm"]/table[2]
이 정상적으로 작동합니다.
그러나 페이지 순서가 변경 될 경우 내 성명서에 친척을 사용하지 마십시오.
두 번째 테이블의 경우 에이전트의 스팬 id 다음에옵니다. 내가 xpath에 스팬 ID 다음의 테이블을 지정할 수 있는지 누가 알 수 있습니까?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<title>Blah</title>
<style type="text/css">
</style>
</head>
<body class="frame">
<div id="container">
<div id="maincontent">
<h1>Details</h1>
<br>
<form name="Form" method="post" action="xxx" id="eForm">
<input type="hidden" name="__VIEWSTATE" value="xxx" />
<table class="summary">
<thead>
<tr>
<th colspan="2">
SUmmary Heading
</th>
</tr>
</thead>
<tr>
<th width="40%">
</th>
<td>
ABC Ltd
</td>
</tr>
<tr>
<th>
Number
</th>
<td>
1234
</td>
</tr>
<tr>
<th>
Company Type
</th>
<td>
Normal Type
</td>
</tr>
<tr>
<th>
Office
</th>
<td>
Street Address is Here
</td>
</tr>
<tr>
<th>
Date of Incorporation
</th>
<td>
24/02/2014
</td>
</tr>
<tr>
<th>
Status
</th>
<td>
LIVE
</td>
</tr>
</table>
<span id="Agent">
<br>
</span>
<table class="summary">
<thead>
<tr>
<th colspan="2">
Agent Details
</th>
</tr>
</thead>
<tr>
<th width="40%">
Registered Agent
</th>
<td>ABC COMPANY LIMITED</td>
</tr>
<tr>
<th>
Agent Address
</th>
<td>Street Address</td>
</tr>
</table>
<!----><br>
<br>
</form>
</div>
</div>
</body>
</html>
감사합니다,하지만 난이 내 응용 프로그램에서 동작하지 않습니다 - 거기에 어떤 도구를 알고 웹 페이지에 대한 구문을 확인하기 위해? – John
@ 존, FireFoxe의 Firebug + Firepath 플러그인을 사용할 수 있습니다. 나는 초기 응답을 편집했다. // // [@ id = 'eForm']''// form [@ id = 'eForm']'또는'// * [@ id = 'eForm' ]' –
@Alexander, 제 대답을 고쳐 주셔서 감사합니다. John Alexander는 Firebug를 사용하여 xpathes를 확인할 수 있다고 말했습니다. 그래도 문제가 있다면 알려주세요. – Andrii