Created
November 5, 2023 20:55
-
-
Save justinledwards/d21b8a20cf9dc302e76222dd919790a6 to your computer and use it in GitHub Desktop.
Get Recommended Junos Versions
This file contains hidden or 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
from playwright.sync_api import sync_playwright | |
from bs4 import BeautifulSoup | |
def extract_data(page_content): | |
soup = BeautifulSoup(page_content, 'html.parser') | |
series_list = ["EX Series Ethernet Switches", "ACX Series Service Routers", | |
"J Series Service Routers", "QFX Series Service Routers", | |
"SRX Series Services Gateways"] | |
for series in series_list: | |
print(f"\n{series}:") | |
table = soup.find('table', summary=series) | |
if table is None: | |
print(f"No table found for {series}") | |
continue | |
rows = table.find_all('tr')[1:] # Skip header row | |
for row in rows: | |
columns = row.find_all('td') | |
anchor = columns[0].find('a') | |
if anchor is None: | |
model_name = columns[0].get_text(strip=True) | |
model_link = None | |
else: | |
model_name = anchor.string | |
model_link = anchor['href'] | |
junos_version = columns[1].string | |
last_updated = columns[2].string | |
print(f"Model: {model_name}, Junos Version: {junos_version}, Last Updated: {last_updated}, Link: {model_link}") | |
def get_recommended_versions(url): | |
with sync_playwright() as p: | |
browser = p.chromium.launch() | |
context = browser.new_context(user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134") | |
page = context.new_page() | |
page.goto(url) | |
# Wait for a table element to appear on the page | |
page.wait_for_selector('table', timeout=10000) # waits for up to 10 seconds | |
page_content = page.content() | |
extract_data(page_content) | |
browser.close() | |
if __name__ == "__main__": | |
url = 'https://supportportal.juniper.net/s/article/Junos-Software-Versions-Suggested-Releases-to-Consider-and-Evaluate?language=en_US' | |
get_recommended_versions(url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment