我在远程服务器上有一个文件列表页面,比如http://myserver.com/uploads
。如何使用Ruby获取文件列表,最好只使用net-http?
这是页面的HTML代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<!-- saved from url=(0025)http://myserver.com/uploads/ -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Index of /uploads</title>
</head>
<body>
<h1>Index of /uploads</h1>
<table>
<tbody>
<tr>
<th><img src="./Index of uploads_files/blank.gif" alt="[ICO]"></th>
<th><a href="http://myserver.com/uploads/?C=N;O=D">Name</a></th>
<th><a href="http://myserver.com/uploads/?C=M;O=A">Last modified</a></th>
<th><a href="http://myserver.com/uploads/?C=S;O=A">Size</a></th>
<th><a href="http://myserver.com/uploads/?C=D;O=A">Description</a></th></tr><tr><th colspan="5"><hr></th>
</tr>
<tr>
<td valign="top"><img src="./Index of uploads_files/back.gif" alt="[DIR]"></td>
<td><a href="http://myserver.com/">Parent Directory</a></td>
<td> </td>
<td align="right"> - </td>
<td> </td>
</tr>
<tr>
<td valign="top"><img src="./Index of uploads_files/compressed.gif" alt="[ ]"></td>
<td><a href="http://myserver.com/uploads/Backup_201305281256.tar.gz">Backup_201305281256.tar.gz</a></td>
<td align="right">28-May-2013 18:00 </td>
<td align="right"> 13M</td><td> </td>
</tr>
<tr><th colspan="5"><hr></th></tr>
</tbody>
</table>
<address>Apache/2.2.22 (Ubuntu) Server at myserver.com Port 80</address>
</body>
</html>
答案 0 :(得分:0)
您看到的是一个HTML页面,其中包含指向HTTP服务器生成的文件的链接。 您需要解析此HTML以获取文件列表,或者使用正则表达式来匹配URI。
查看URI regex。