Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >>> from urllib.parse import urlparse # python2: from urlparse import urlparse
- >>> urlparse('actually not a url')
- ParseResult(scheme='', netloc='', path='actually not a url', params='', query='', fragment='')
- >>> urlparse('http://google.com')
- ParseResult(scheme='http', netloc='google.com', path='', params='', query='', fragment='')
- import urllib.request as req
- import urllib.parse as p
- def foo():
- url = 'http://bar.com'
- request = req.Request(url)
- try:
- response = req.urlopen(request)
- #response is now a string you can search through containing the page's html
- except:
- #The url wasn't valid
- import validators
- url = 'YOUR URL'
- validators.url(url)
Add Comment
Please, Sign In to add comment