如何以編程方式解析Firefox的版本號。以編程方式獲取最新版本Firefox的編號
因此,我不必每次都訪問該頁面。 我所要做的就是運行腳本,它會給我最新版本。
http://download.cdn.mozilla.net/pub/mozilla.org/firefox/releases/latest/update/win32/en-US/
該文件將始終具有 「.complete.mar」 在裏面。這是該目錄下唯一帶有「完成」字樣的文件。 如何從中解析版本「40.0.2」。
如何以編程方式解析Firefox的版本號。以編程方式獲取最新版本Firefox的編號
因此,我不必每次都訪問該頁面。 我所要做的就是運行腳本,它會給我最新版本。
http://download.cdn.mozilla.net/pub/mozilla.org/firefox/releases/latest/update/win32/en-US/
該文件將始終具有 「.complete.mar」 在裏面。這是該目錄下唯一帶有「完成」字樣的文件。 如何從中解析版本「40.0.2」。
您將遇到問題,因爲您要檢查的數據不在同一個域中。
但是,您可以使用類似node webkit(現在的nwjs)來通過瀏覽器限制。
提取內容。
下載JQuery並將其放置在解壓縮的文件夾中(重命名文件jquery.js)。
創建一個新的文本文件,添加以下內容並保存爲的package.json
的package.json內容:
{
"main": "index.html",
"name": "firefoxversion",
"version": "1",
"window": {
"title": "latest firefox version",
"icon": "link.png",
"toolbar": true,
"width": 800,
"height":600
}
}
創建一個文件名index.html,然後保存以下內容:
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>
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
簡單的答案是Mozilla Release Engineering已經提供了一種下載最新版本的方法。請參閱https://ftp.mozilla.org/pub/firefox/releases/latest/README.txt
例如,我想要下載最新的Linux 64位美國英語版的Firefox。所以我會:
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
請注意,這些是穩定版本,而不是RC或每晚。對於那些看release notes in the appropriate subfolder。
注:
curl
命令URL由單引號('
)包圍,以避免的bash解釋符號(&
)。$PATH
(或Windows中的%PATH%
)環境變量的開頭添加您下載的Firefox。如果您從捲曲中獲得問題,請嘗試在鏈接周圍替換單引號(')與雙引號(「) – jenesaisquoi
因爲我必須知道許多應用程序的最新版本號,所以我創建了名爲vergrabber的在線服務,它在json中提供了這些信息。 你可以試試這個免費服務http://vergrabber.kingu.pl/vergrabber.json
太棒了!它效果很好。 – Imsa
現在,有沒有辦法使用該版本號並將其導出到文件?或者使用解析後的版本並將其添加到URL的末尾,以將其用作鏈接以下載文件。目標是動態查找最新版本,然後下載最新的.mar文件。 – Imsa
不應該是一個問題我會處理它並編輯我的答案 –