Surya_from_1627

WSP2

Sep 7th, 2026 (edited)
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. import requests
  2.  
  3. def fetch_robots_txt(domain):
  4.     url = f"https://{domain}/robots.txt"
  5.     try:
  6.         headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'}
  7.         response = requests.get(url, headers=headers)
  8.         if response.status_code == 200:
  9.             print(f"✅ robots.txt content from {domain}:\n")
  10.             print(response.text)
  11.         else:
  12.             print(f"⚠️ Failed to retrieve robots.txt. Status code: {response.status_code}")
  13.     except requests.exceptions.RequestException as e:
  14.         print(f"❌ Error fetching robots.txt: {e}")
  15.  
  16. # Example usage
  17. fetch_robots_txt("en.wikipedia.org")
Advertisement
Add Comment
Please, Sign In to add comment