是否可以读取大型网页的最后几行(或1000个字符)?(is it possible to read the last few lines (or 1000 characters say) of a l

编程入门 行业动态 更新时间:2024-10-24 01:57:17
是否可以读取大型网页的最后几行(或1000个字符)?(is it possible to read the last few lines (or 1000 characters say) of a large web page?)

我们需要每5分钟轮询一次网页,并且网页正在变得相当大。 网页是一个目录列表,我们需要最后一行(获取文件名)。 得到最后一行的最佳方式是什么?

(如果这是一个本地文件,我可以在文件末尾找一个相对位置并读取)。

We need to poll a web page every 5 minutes and the web page is growing rather large. The web page is a directory listing and we need the last line (to get a file name). What is the best way to get just this last line?

(If this was a local file I could position back a little relative to the end of file and read).

最满意答案

HTTP 1.1确实支持一组标题来只请求特定范围的字节,包括仅支持文件的最后n个字节(使用“后缀”格式)。 看到这里 。 例如,

Range: bytes=-1000

为最后的1000字节。 (当然,假设服务器支持Range标头。)

HTTP 1.1 does support a set of headers to request only a particular range of bytes, including support for just the last n bytes of a file (using the "suffix" format). See here. For instance,

Range: bytes=-1000

for the last 1000 bytes. (Assuming the server supports the Range header, of course.)

更多推荐

本文发布于:2023-08-07 07:48:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1462365.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符   几行   网页   read   page

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!