I have to check whether url exists or not using python. I am trying to use requests.get(url) but it is taking alot of time as the file starts downloading as soon as get is hit. I don't want the file to be downloaded for checking the url validity. Can this be achieved using python ?
Something like the below. See HTTP head for more info.
import requests
urls = ['https://www.google.com','https://www.google.com/you_can_not_find_me']
for idx,url in enumerate(urls,1):
r = requests.head(url)
if r.status_code == 200:
print(f'{idx}) {url} was found')
else:
print(f'{idx}) {url} was NOT found')
output
1) https://www.google.com was found
2) https://www.google.com/you_can_not_find_me was NOT found
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With