Created
March 30, 2025 14:23
-
-
Save zengxinhui/c6019b8d01ab4376a985c46d16c06894 to your computer and use it in GitHub Desktop.
parse junos eol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re, requests | |
from lxml import html | |
url = 'https://support.juniper.net/support/eol/software/junos/' | |
headers = { | |
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3' | |
} | |
response = requests.get(url, headers=headers) | |
htmltext = re.findall(r'<table>.*</table>', response.content.decode('utf-8')) | |
tree = html.fromstring(htmltext[0]) | |
target_table = None | |
for table in tree.xpath('//table'): | |
headers = [th.text_content().strip() for th in table.xpath('.//th')] | |
if 'Product' in headers and 'FRS Date' in headers: | |
target_table = table | |
break | |
data = [] | |
for row in target_table.xpath('.//tr'): | |
if row.xpath('.//th'): | |
continue | |
cols = row.xpath('.//td/text()') | |
data.append(cols) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment