Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.26 KB | None | 0 0
  1. import requests
  2.  
  3.  
  4. def getting_url():
  5.     try:
  6.         url = input("Type url that you want to crawl (example - https://blablabla.com): ").replace(" ", "")
  7.  
  8.         if "https" not in url or "http" not in url:
  9.             print("You need to specify protocol of the page")
  10.             getting_url()
  11.         else:
  12.             if "://www." in url:
  13.                 final_url = url.replace("www.", "")
  14.                 if ".com" in url:
  15.                     r = requests.head(final_url)
  16.                     if r.status_code == 200:
  17.                         return final_url
  18.                     else:
  19.                         print("Url doesn't exist")
  20.                 else:
  21.                     print("Url is not valid.")
  22.                     getting_url()
  23.             else:
  24.                 if ".com" in url:
  25.                     r = requests.head(url)
  26.                     if r.status_code == 200:
  27.                         return url
  28.                     else:
  29.                         print("Url doesn't exist")
  30.                 else:
  31.                     print("Url is not valid.")
  32.                     getting_url()
  33.  
  34.     except KeyboardInterrupt:
  35.         print("\nQuiting")
  36.  
  37.     except:
  38.         print("Url doesn't exist")
  39.         getting_url()
  40.  
  41. print(getting_url())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement