0

我在远程服务器上有一个文件列表页面,比如说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>&nbsp;</td>
                    <td align="right">  - </td>
                    <td>&nbsp;</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>&nbsp;</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>
4

1 回答 1

0

您看到的是一个 HTML 页面,其中包含指向 HTTP 服务器生成的文件的链接。您需要解析此 HTML 以获取文件列表,或者您使用正则表达式来匹配 URI。

看看URI 正则表达式

于 2013-05-31T10:46:22.567 回答