I don't want to check if a ISBN is valid.
I'm trying to figure out if, given a ISBN isbn
, there's already a book associated with it.
What I already tried
I was planning to use the following function:
import requests
def is_isbn_already_used(isbn:str)->bool:
""" Given a ISBN string, returns True if there's a
book already associated with it"""
# Tries to search ISBN in the below site
response = requests.get("https://isbnsearch.org/isbn/" isbn)
# checks if the site doesn't have any info about that isbn
return not ("Not Found" in response.text)
The problem is: The part where the function gets the text of the page doesn't works as I expected. Probably, because the site is dynamic, it waits a few ms before showing the info about the book.
I was thinking of dealing with Selenium's Webdriver for Firefox, but then I would need to deal with the captcha.
Any idea would be appreciated.
CodePudding user response:
Well, I'll answer my own question: I decided to use the Google Books' API.
Worth noting that this API is non-strict when it searches for ISBNs: Searching for a ISBN that is not officially associated with any book, like 9780062059942, will return a book with an ISBN closely associated with 9780062059942: The Selection, in this case.
So, I modified my function:
from requests import get
def check_isbn_already_associated(isbn:str)->bool:
"""Returns True if this isbn is already associated with a book"""
response = get("https://www.googleapis.com/books/v1/volumes?q=isbn:" isbn)
return isbn in response.text