mayankjoin3

extract web links url bootstrap local

Jun 26th, 2026
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.76 KB | None | 0 0
  1. import os
  2. import re
  3.  
  4. # ---------- CONFIG ----------
  5. ROOT_DIR = r"C:\Users\Mayank\Documents\GitHub\ERP"
  6. OUTPUT_FILE = "web_links.txt"
  7.  
  8. # Regex to extract http/https URLs
  9. url_pattern = re.compile(
  10.     r'https?://[^\s\'"<>()]+',
  11.     re.IGNORECASE
  12. )
  13.  
  14. urls = set()
  15.  
  16. # ---------- SCAN ----------
  17. for root, _, files in os.walk(ROOT_DIR):
  18.     for file in files:
  19.  
  20.         if not file.lower().endswith(".php"):
  21.             continue
  22.  
  23.         full_path = os.path.join(root, file)
  24.  
  25.         try:
  26.             with open(full_path, "r", encoding="utf-8", errors="ignore") as f:
  27.                 content = f.read()
  28.  
  29.             matches = url_pattern.findall(content)
  30.  
  31.             for url in matches:
  32.  
  33.                 # Remove trailing punctuation
  34.                 url = url.rstrip(''''",);]}''')
  35.  
  36.                 # Ignore localhost / local IPs
  37.                 if (
  38.                     "localhost" in url.lower()
  39.                     or "127.0.0.1" in url
  40.                     or "0.0.0.0" in url
  41.                     or url.startswith("http://192.168.")
  42.                     or url.startswith("https://192.168.")
  43.                     or url.startswith("http://10.")
  44.                     or url.startswith("https://10.")
  45.                     or url.startswith("http://172.")
  46.                     or url.startswith("https://172.")
  47.                 ):
  48.                     continue
  49.  
  50.                 urls.add(url)
  51.  
  52.         except Exception as e:
  53.             print(f"Error reading {full_path}: {e}")
  54.  
  55. # ---------- EXPORT ----------
  56. with open(OUTPUT_FILE, "w", encoding="utf-8") as f:
  57.  
  58.     f.write(f"Total unique URLs: {len(urls)}\n\n")
  59.  
  60.     for url in sorted(urls):
  61.         f.write(url + "\n")
  62.  
  63. print(f"Found {len(urls)} unique web URLs.")
  64. print(f"Saved to {OUTPUT_FILE}")
Advertisement
Add Comment
Please, Sign In to add comment