Guest User

Untitled

a guest
Jul 17th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. >>> from urllib.parse import urlparse # python2: from urlparse import urlparse
  2. >>> urlparse('actually not a url')
  3. ParseResult(scheme='', netloc='', path='actually not a url', params='', query='', fragment='')
  4. >>> urlparse('http://google.com')
  5. ParseResult(scheme='http', netloc='google.com', path='', params='', query='', fragment='')
  6.  
  7. import urllib.request as req
  8. import urllib.parse as p
  9.  
  10. def foo():
  11. url = 'http://bar.com'
  12. request = req.Request(url)
  13. try:
  14. response = req.urlopen(request)
  15. #response is now a string you can search through containing the page's html
  16. except:
  17. #The url wasn't valid
  18.  
  19. import validators
  20. url = 'YOUR URL'
  21. validators.url(url)
Add Comment
Please, Sign In to add comment