Home > Enterprise >  How can I extract Azure IP ranges json file programatically through python?
How can I extract Azure IP ranges json file programatically through python?

Time:05-04

I want to download the ipranges.json (which is updated weekly) from enter image description here

We realize the file will change after a while, so we have to scrape it in generic way

For convenience, I will not use wget, 2 libraries here are requests to request page and download file, beaufitulsoup to parse html

# pip install requests
# pip install bs4
import requests
from bs4 import BeautifulSoup

# request page
URL = "https://www.microsoft.com/en-us/download/confirmation.aspx?id=56519"
page = requests.get(URL)

# parse HTML to get the real link
soup = BeautifulSoup(page.content, "html.parser")
link = soup.find('a', {'data-bi-containername':'download retry'})['href']

# download
file_download = requests.get(link)

# save in azure_ips.json
open("azure_ips.json", "wb").write(file_download.content)
  • Related