I want to check with a boolean request, if there is a picture on the website:
https://portal.dnb.de/opac/mvb/cover?isbn=9783442472352
or not:
https://portal.dnb.de/opac/mvb/cover?isbn=3499239663
I don`t know how that is possible.
Thank you for your help!!
Advertisement
Answer
Looks like you should deal with response status – for selenium
, take a read:
How to get status code by using selenium.py (python code)
Alternative approach, get the status
with requests
:
JavaScript
x
9
1
import requests
2
urls = ['https://portal.dnb.de/opac/mvb/cover?isbn=9783442472352','https://portal.dnb.de/opac/mvb/cover?isbn=3499239663']
3
for url in urls:
4
r = requests.get(url)
5
if r.status_code == 200:
6
print(url, ': yeah, there seems to be an image')
7
elif r.status_code == 400:
8
print(url, ': nope, no image here')
9
Output
JavaScript
1
3
1
https://portal.dnb.de/opac/mvb/cover?isbn=9783442472352 : yeah, there seems to be an image
2
https://portal.dnb.de/opac/mvb/cover?isbn=3499239663 : nope, no image here
3