how can I get the file version on the Internet but not download it?

空扰寡人 提交于 2020-01-04 04:05:49

问题


I get a file url,for example, http://cidian.youdao.com/download/YoudaoDict.exe

how can I get it's version but not download it ?

nots 1: if you download the file first on your computer,there are many ways to get it's

version, for example ,you can use the window tools "filever.exe" to get the version.

but i want to not download it ,at least not download it all.how can I do? Waiting your

help! thanks.

nots 2: I have tried the way to get a portion of the file to get the version:

first, I used the download tool "wget.exe" to download a portion of the file ( wget.exe is

a single-threaded download tool,it can make sure download form the head)

second, I used the "filever.exe" to get the file version.

In this way, some software i can get it's version,but some cann't(they must all be

downloaded).I don't know why.


回答1:


I notice that that particular exe link supports byte range requests.

$ curl -I http://cidian.youdao.com/download/YoudaoDict.exe
HTTP/1.1 200 OK
...
Accept-Ranges: bytes
Content-Length: 4820792
...
Content-Type: application/octet-stream

You could make one or more HTTP byte range request to get the parts of the file you need to determine the version. You'd just be making several requests to get the parts of the file you'd look at if it were on your hard drive.

For example, based on the HTTP/1.1 spec, you can request the first 500 bytes with this request header:

curl -H"Range: bytes=0-499" http://... -o bytes-0-499.dat



回答2:


Version numbers, if any, are embedded in the .exe file itself. You will have to download at least a portion of the file to retrieve these bits of metadata.

Check out the .exe file format spec.




回答3:


You can do an HTTP HEAD request, and the server may report the size of the item in Content-Length. It may also report a version under the Last-Modified header. Further, ETag may be present for the same purpose.

You can test this with netcat:

> nc cidian.youdao.com 80
HEAD /download/YoudaoDict.exe HTTP/1.1
Host: cidian.youdao.com

HTTP/1.1 200 OK
Date: Mon, 10 Aug 2009 06:11:59 GMT
Server: Apache
ETag: "Dcm1w6Vxg51"
Last-Modified: Sat, 08 Aug 2009 02:18:40 GMT
Accept-Ranges: bytes
Content-Length: 4820792
X-Request-Received: t=1249884719506801
X-Request-Processing-Time: D=906244
Content-Type: application/octet-stream

As you can see, in your example case, all three headers are given, so you can guess version changes based on that information. I'd always check to insure Date and Last-Modified aren't the same, as sometimes the latter is set to the former for pages generated by scripts.




回答4:


Well in theory this is the kind of task that an HTTP HEAD request is designed for but iirc the only relevant info you'd get by default (if the request was handled at all of course) would be Content-Length and Last-Modified. Edit: and ETag!

That probably gets you much of what you need to know, but if you really wanted to have version number you'd have to be in control of the web service and be able to obtain and append that information to the response headers. Not so hard to do but only if you have control of the service.




回答5:


If your purpose is to detect when a new version becomes available, you could look at the response of a HEAD HTTP request as others have suggested.

Otherwise, you could screen scrape the (download page) and extract the latest version details. There is a convenient <dl id="downloadSth"> tag within which version info is listed and could conceivably be harvested. I have no idea whether this is going to be reliable; the site's authors could change this without notice.

I'd look at using BeautifulSoup for this.



来源:https://stackoverflow.com/questions/1253282/how-can-i-get-the-file-version-on-the-internet-but-not-download-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!