import requests from bs4 import BeautifulSoup headers = {"User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36"} r = requests.get("https://lite.ip2location.com/...your-country...-ip-address-ranges", headers = headers) txt = r.text f = open("_ranges.txt","w") soup = BeautifulSoup(txt,"lxml") tbody = soup.find("tbody") rows = tbody.find_all("tr") for row in rows: cols = row.find_all("td") start = cols[0].text stop = cols[1].text iplen = int(cols[2].text.replace(",","")) if iplen >= 128: print start, stop, iplen f.write(start + "-" + stop + "\n") f.close()