Nokogiri, Mechanize 및 XPath를 사용하여 페이지를 구문 분석하려고하지만, 시도 할 때마다 빈 배열이 나타납니다. Nokogiri를 사용하여 빈 배열을 반환하는 XPath
나는 크롬에서 그것을 검사하고 XPath를 가지고, 다음의 구문을 분석하기 위해 여러 가지 방법을 시도했지만 항상 빈 배열을 받았다.내가 시도 :
puts page.search('/html/body/div/table/tbody/tr[2]/td/table/tbody/tr[2]/td[2]').inspect
puts post_page.parser.xpath('/html/body/div/table/tbody/tr[2]/td/table/tbody/tr[2]/td[2]').inspect
puts post_page.parser.at_xpath('/html/body/div/table/tbody/tr[2]/td/table/tbody/tr[2]/td[2]').inspect
모두 "/ 텍스트"
와 후행하지 않고이 내가 긁어하기 위해 노력하고있어 페이지의 소스입니다 :
<SCRIPT language="JavaScript">
<!--
document.cookie = "IV_JCT=%2FMPIS; path=/";
//-->
</SCRIPT>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My Schedule</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="-1">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my schedule">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<div align="center">
<strong>My Schedule</strong><br>as of Sun Feb 24 2013 06:43:09 PM CST<br><br>
<div align="left"><pre><br>Employee Name: Johnson Appleseed
Unit = 12345</pre>
<br>
</div>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="8" align="center"><b><font size="+1">Schedules may be subject to change based on business needs or demand</font></b></td>
</tr>
<tr><td>
<table border="4" bordercolor="#2D73B9" cellpadding="2" cellspacing="2" width="100%">
<tr bgcolor="#7C9BCF">
<td width="12%" align="center"><b>Sunday</b></td>
<td width="12%" align="center"><b>Monday</b></td>
<td width="12%" align="center"><b>Tuesday</b></td>
<td width="12%" align="center"><b>Wednesday</b></td>
<td width="12%" align="center"><b>Thursday</b></td>
<td width="12%" align="center"><b>Friday</b></td>
<td width="12%" align="center"><b>Saturday</b></td>
<td rowspan="2" width="12%" align="center"><b>Total weekly Hours</b></td>
</tr>
<tr bgcolor="#7C9BCF">
<td width="14%" align="center">2013-02-24</td>
<td width="14%" align="center">2013-02-25</td>
<td width="14%" align="center">2013-02-26</td>
<td width="14%" align="center">2013-02-27</td>
<td width="14%" align="center">2013-02-28</td>
<td width="14%" align="center">2013-03-01</td>
<td width="14%" align="center">2013-03-02</td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="14%" align="left"><pre> </pre></td>
<td width="14%" align="left"><pre><b>Shift: </b>
5:30 PM - 9:00 PM
<b>Meal:</b>
- </pre></td>
<td width="14%" align="left"><pre> </pre></td>
<td width="14%" align="left"><pre> </pre></td>
<td width="14%" align="left"><pre> </pre></td>
<td width="14%" align="left"><pre><b>Shift: </b>
2:00 PM - 9:15 PM
<b>Meal:</b>
5:45 PM - 6:30 PM</pre></td>
<td width="14%" align="left"><pre><b>Shift: </b>
4:45 PM - 9:15 PM
<b>Meal:</b>
- </pre></td>
<td width="12%" align="center">14.5</td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="14%" align="center">0.0</td>
<td width="14%" align="center">3.5</td>
<td width="14%" align="center">0.0</td>
<td width="14%" align="center">0.0</td>
<td width="14%" align="center">0.0</td>
<td width="14%" align="center">6.5</td>
<td width="14%" align="center">4.5</td>
<td width="14%" align="center">Daily Hours</td>
</tr>
</table>
</td></tr>
<tr><td>
<table border="4" bordercolor="#2D73B9" cellpadding="2" cellspacing="2" width="100%">
<tr bgcolor="#7C9BCF">
<td width="12%" align="center"><b>Sunday</b></td>
<td width="12%" align="center"><b>Monday</b></td>
<td width="12%" align="center"><b>Tuesday</b></td>
<td width="12%" align="center"><b>Wednesday</b></td>
<td width="12%" align="center"><b>Thursday</b></td>
<td width="12%" align="center"><b>Friday</b></td>
<td width="12%" align="center"><b>Saturday</b></td>
<td rowspan="2" width="12%" align="center"><b>Total weekly Hours</b></td>
</tr>
<tr bgcolor="#7C9BCF">
<td width="14%" align="center">2013-03-03</td>
<td width="14%" align="center">2013-03-04</td>
<td width="14%" align="center">2013-03-05</td>
<td width="14%" align="center">2013-03-06</td>
<td width="14%" align="center">2013-03-07</td>
<td width="14%" align="center">2013-03-08</td>
<td width="14%" align="center">2013-03-09</td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="14%" align="left"><pre>Sched Not Posted</pre></td>
<td width="14%" align="left"><pre>Sched Not Posted</pre></td>
<td width="14%" align="left"><pre>Sched Not Posted</pre></td>
<td width="14%" align="left"><pre>Sched Not Posted</pre></td>
<td width="14%" align="left"><pre>Sched Not Posted</pre></td>
<td width="14%" align="left"><pre>Sched Not Posted</pre></td>
<td width="14%" align="left"><pre>Sched Not Posted</pre></td>
<td width="12%" align="center">0.0</td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="14%" align="center">0.0</td>
<td width="14%" align="center">0.0</td>
<td width="14%" align="center">0.0</td>
<td width="14%" align="center">0.0</td>
<td width="14%" align="center">0.0</td>
<td width="14%" align="center">0.0</td>
<td width="14%" align="center">0.0</td>
<td width="14%" align="center">Daily Hours</td>
</tr>
</table>
</td></tr>
<tr><td>
<table border="4" bordercolor="#2D73B9" cellpadding="2" cellspacing="2" width="100%">
<tr bgcolor="#7C9BCF">
<td width="12%" align="center"><b>Sunday</b></td>
<td width="12%" align="center"><b>Monday</b></td>
<td width="12%" align="center"><b>Tuesday</b></td>
<td width="12%" align="center"><b>Wednesday</b></td>
<td width="12%" align="center"><b>Thursday</b></td>
<td width="12%" align="center"><b>Friday</b></td>
<td width="12%" align="center"><b>Saturday</b></td>
<td rowspan="2" width="12%" align="center"><b>Total weekly Hours</b></td>
</tr>
<tr bgcolor="#7C9BCF">
<td width="14%" align="center">2013-03-10</td>
<td width="14%" align="center">2013-03-11</td>
<td width="14%" align="center">2013-03-12</td>
<td width="14%" align="center">2013-03-13</td>
<td width="14%" align="center">2013-03-14</td>
<td width="14%" align="center">2013-03-15</td>
<td width="14%" align="center">2013-03-16</td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="14%" align="left"><pre>Sched Not Posted</pre></td>
<td width="14%" align="left"><pre>Sched Not Posted</pre></td>
<td width="14%" align="left"><pre>Sched Not Posted</pre></td>
<td width="14%" align="left"><pre>Sched Not Posted</pre></td>
<td width="14%" align="left"><pre>Sched Not Posted</pre></td>
<td width="14%" align="left"><pre>Sched Not Posted</pre></td>
<td width="14%" align="left"><pre>Sched Not Posted</pre></td>
<td width="12%" align="center">0.0</td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="14%" align="center">0.0</td>
<td width="14%" align="center">0.0</td>
<td width="14%" align="center">0.0</td>
<td width="14%" align="center">0.0</td>
<td width="14%" align="center">0.0</td>
<td width="14%" align="center">0.0</td>
<td width="14%" align="center">0.0</td>
<td width="14%" align="center">Daily Hours</td>
</tr>
</table>
</td></tr>
<tr>
<td colspan="8" align="center"><b><font size="+1">Schedules may be subject to change based on business needs or demand</font></b></td>
</tr>
</table >
<p><br>
</p>
<p class="align_center" >
<input type=button value="Print this page" onClick="javascript:window.print();">
<input type=button value="Close This Window" onClick="javascript:window.close();">
</p>
</div>
</body>
</html>
HTML과 같은 코드 또는 데이터를 제공 할 때 문제를 설명/재현하는 데 필요한 최소 수준으로 줄이십시오.그것보다 더 많은 것이 우리 시간을 낭비하고 우리가 당신을 도울 수있는 길을 얻습니다. 또한, 당신은 당신이 성취하려는 것을 말하지 않습니다. –