
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Validate a URL with Regular Expression in Python
There's no validate method as almost anything is a valid URL. There are some punctuation rules for splitting it up. Without any punctuation, you still have a valid URL.
Depending on the situation, we use following methods.
If you trust the data, and just want to verify if the protocol is HTTP, then urlparse is perfect.
If you want to make the URL is actually a true URL, use the cumbersome and maniacal regex
If you want to make sure it's a real web address, use the following code
Example
import urllib try: urllib.urlopen(url) except IOError: print "Not a real URL"
Advertisements