简体   繁体   English

以编程方式获取Firefox的最新版本号

[英]Programatically Get the Latest Version Number of Firefox

How can I parse the version number of Firefox programatically. 如何以编程方式解析Firefox的版本号。

So, I don't have to visit the page every time. 因此,我不必每次都访问该页面。 All I would have to do is run the script, and it will give me the latest version. 我所要做的就是运行脚本,它将为我提供最新版本。

http://download.cdn.mozilla.net/pub/mozilla.org/firefox/releases/latest/update/win32/en-US/ http://download.cdn.mozilla.net/pub/mozilla.org/firefox/releases/latest/update/win32/zh-CN/

The file will always have ".complete.mar" in it. 该文件将始终包含“ .complete.mar”。 It's the only file with the word "complete" under this directory. 这是该目录下唯一带有单词“ complete”的文件。 How can I parse the version "40.0.2" from it. 如何从中解析版本“ 40.0.2”。

Because I have to know the lastest version numbers of many applications, I've created the online service called vergrabber which provides that information in json. 因为我必须知道许多应用程序的最新版本号,所以我创建了名为vergrabber的在线服务,该服务在json中提供了该信息。 You may try this free service at http://vergrabber.kingu.pl/vergrabber.json 您可以在http://vergrabber.kingu.pl/vergrabber.json上尝试此免费服务

Download the latest release 下载最新版本

The simple answer is Mozilla Release Engineering already provides a way to download the latest version. 简单的答案是Mozilla Release Engineering已经提供了下载最新版本的方法。 See https://ftp.mozilla.org/pub/firefox/releases/latest/README.txt 参见https://ftp.mozilla.org/pub/firefox/releases/latest/README.txt

For example, I want to download the latest Linux 64-bit US English version of Firefox. 例如,我要下载最新的Linux 64位美国英语版本的Firefox。 So I would: 所以我会:

curl -Lo firefox.tar.bz2 'https://download.mozilla.org/?product=firefox-latest&os=linux64&lang=en-US'
tar -xjf firefox.tar.bz2
cd firefox
./firefox --version

Mind you those are stable releases and not RC or nightly. 请注意,这些是稳定版本,而不是RC或每晚发布。 For those see release notes in the appropriate subfolder . 有关这些信息,请参见相应子文件夹中的发行说明

Notes: 笔记:

  • The curl command URL is surrounded by single quotes ( ' ) to avoid bash interpreting the ampersands ( & ). curl命令URL由单引号(包围' ),以避免bash的解释和符号( & )。
  • You would likely want to add your downloaded Firefox at the beginning of the $PATH (or %PATH% in Windows) environment variable. 您可能希望将下载的Firefox添加到$PATH (或Windows中的%PATH% )环境变量的开头。

Get latest release version number 获取最新发行版本号

To get the latest version number without downloading the archive you would use the HTTP HEAD method ( curl -I option). 要获得最新版本号而不下载存档,可以使用HTTP HEAD方法( curl -I选项)。 Example, 例,

curl -fI 'https://download.mozilla.org/?product=firefox-latest&os=linux64&lang=en-US' | grep -o 'firefox-[0-9.]\+[0-9]'

which will return something like firefox-67.0.4 . 这将返回类似于firefox-67.0.4

You are going to run into problems because the data you want to check is not within the same domain. 您将遇到问题,因为您要检查的数据不在同一域中。

You can however using something like node webkit(now nwjs) to get pass the browser limitation. 但是,您可以使用诸如node webkit(现在为nwjs)之类的内容来通过浏览器限制。

  1. To start download the nodewebkit files for your operating system from the following link: 要从以下链接开始为您的操作系统下载nodewebkit文件:

http://nwjs.io/ http://nwjs.io/

  1. Extract the contents. 提取内容。

  2. Download JQuery and place it in the extracted folder(rename the file jquery.js). 下载JQuery并将其放在提取的文件夹中(将文件重命名为jquery.js)。

  3. create a new text file, add the following contents and save it as package.json 创建一个新的文本文件,添加以下内容并将其另存为package.json

package.json contents: package.json内容:

{
  "main": "index.html",
  "name": "firefoxversion",
  "version": "1",
  "window": {
    "title": "latest firefox version",
    "icon": "link.png",
    "toolbar": true,
    "width": 800,
    "height":600
   }
}

Create a file name index.html and save the following contents: 创建一个文件名index.html并保存以下内容:

index.html contents: index.html内容:

<html>
    <head>
        <title>Latest Firefox Version</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>

        <div id="result"></div>




        <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript" src="main.js"></script>
    </body>
</html>
  1. Next create a file named main.js and save the following contents: 接下来创建一个名为main.js的文件并保存以下内容:

main.js contents: main.js内容:

var url ="http://download.cdn.mozilla.net/pub/mozilla.org/firefox/releases/latest/update/win32/en-US/";


var version;

$.get(url,function(data){//begin function


$(data).contents().find("a").each(function(){//begin each function


//create an array to hold the hmtl
var html = [];


if($(this).attr("href").indexOf("complete.mar" !== -1 )){//begin if then


version = $(this).attr("href").split(".c");


//start building your html to output
html.push("Download the latest Firefox Version " + version[0] + " below:<br>");

//add the download button
html.push("<input type ='button' id ='firefox-latest' value = 'Download Firefox'>");


//display the html in the #result div
$("#result").html(html.join(""));


}//end if then


});//end each function




});//end function

//on click event for #firefox-latest
$(document).on("click","#firefox-latest",function(){//begin on click event

//change the window location to the file for the latest firefox version
window.location.href = url + version[0] + ".complete.mar";


});//end on click event
  1. Lastly click on the nw.exe icon inside of the folder you extracted earlier and you should see the latest version number of firefox. 最后,单击您先前提取的文件夹内的nw.exe图标,您应该会看到最新版本的firefox。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM