Reputation: 137
I found this code:
import webbrowser
webbrowser.open('http://eample.com')
How do I modify it so that it will only open the link if the return code is 200?
Upvotes: 1
Views: 583
Reputation: 16711
Use the requests
package to send a HEAD
request to the desired location and then create an if
if requests.head(url).status_code == 200: webbrowser.open(url) # open url if status is 200
Upvotes: 3