Skip to content

Instantly share code, notes, and snippets.

@sgraaf
Created September 15, 2022 12:54
Show Gist options
  • Save sgraaf/9df4a2b2aa3fb7c3ee67626f07d12359 to your computer and use it in GitHub Desktop.
Save sgraaf/9df4a2b2aa3fb7c3ee67626f07d12359 to your computer and use it in GitHub Desktop.
Scrape recent Chrome and Firefox version numbers
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Get Firefox versions (Major)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Imports"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"from lxml import html"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Preamble"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"url = \"https://www.mozilla.org/en-US/firefox/releases/\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Main"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"with open(\"firefox_versions.txt\", \"r\", encoding=\"utf-8\") as fh:\n",
" versions = fh.read().splitlines()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"versions = []"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"r = requests.get(url)\n",
"tree = html.fromstring(r.content)\n",
"\n",
"new_versions = [version for version in tree.xpath('//ol[@class=\"c-release-list\"]/li/strong/a/text()') if version not in versions]\n",
"new_versions.remove(\"14.0.1\")\n",
"new_versions = sorted(new_versions, key=float)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"new_versions"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"if new_versions:\n",
" with open(\"firefox_versions.txt\", \"a\", encoding=\"utf-8\") as fh:\n",
" for version in sorted(new_versions):\n",
" fh.write(version + \"\\n\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"interpreter": {
"hash": "304af0c388573785794e9f0a925230dd9ce2d854780d50013a3eb97f55f45953"
},
"kernelspec": {
"display_name": "Python 3.9.9 64-bit ('.venv': venv)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.9"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment