How to check if Hyperlinks are valid or not

[How to check if Hyperlinks are valid or not]

[Programming Language]: Python
[Version]: 2.5+
[Purpose]: This Code sample checks if the provided link is valid or not

In many cases, you want to check the validity of the hyperlinks before you insert them in to your database. We can check the syntax of the hyperlinks using Regex, however to check if hyperlink is broken or not - we have to check http response by making request to the supplied hyperlink.

[Steps By Steps Instructions]

1. Open up your favorite Python Editor. I used the Python IDLE - type in the code as shown in the figure 1.



2. Done typing in the code. Execute the code. For the first URL www.cnn.com - you should get the message which says that url is valid see the figure 2.



3. Now change the url to www.3cnn.com or any invalid URL (see figure 3) and review the response as shown in the figure 4.



Comments
Advertisements
Zimbio Entertainment
Copyright © 2012 - Zimbio, Inc. Some rights reserved. Coming soon: Livingly
Share
. . .
Follow
. . .