# BOOKY SI APPOGGIA SU GOOGLE BOOKS
# https://booky-andy.herokuapp.com/query?search=prova

import requests
import pandas as pd
import json
from bs4 import BeautifulSoup
import time
import random
import re
timeout = 30
start_page = 1
end_page = 999999
for index in range(start_page, end_page+1):
    main_link = 'https://browse.nypl.org/iii/encore/search/C__S%28*%29%20f%3Aa%20l%3Aeng%20y%3A%5B2019-2021%5D__Orightresult__U?lang=eng&suite=def'
    main_page = requests.get(main_link, timeout=timeout)
    soup_main = BeautifulSoup(main_page.text, "html.parser")
    book_link = soup_main.find_all('a', id=re.compile('.*recordDisplayLink2.*'), href=True)
    title_list = []
    link_book = []
    isbn_10_lst = []
    for book in book_link:
        title = book.text
        book_link = book['href']
        if title:
            title_list.append(title.strip())
        else:
            title_list.append('')
        if book_link:
            book_link = 'https://browse.nypl.org/'+book_link
            link_book.append(book_link)
            soup_details = requests.get(book_link, timeout=timeout)
            isbn_div = soup_details.find('td', {'class': 'bibInfoData'})[1]
            if (isbn_div):
                isbn_10_lst.append(isbn_div.text.strip())
            else:
                isbn_10_lst.append('')
        else:
            link_book.append('')
        next_link = soup_main.find('a', id=f'.*searchPageLink_{index+1}.*', href=True)['href']
        main_link = 'https://browse.nypl.org/'+next_link
        print(zip(title_list, isbn_10_lst))

# BOOKY SI APPOGGIA SU GOOGLE BOOKS
# https://booky-andy.herokuapp.com/query?search=prova

import requests
import pandas as pd
import json
from bs4 import BeautifulSoup
import time
import random
import re
timeout = 30
start_page = 1
end_page = 999999
for index in range(start_page, end_page+1):
    main_link = 'https://browse.nypl.org/iii/encore/search/C__S%28*%29%20f%3Aa%20l%3Aeng%20y%3A%5B2019-2021%5D__Orightresult__U?lang=eng&suite=def'
    main_page = requests.get(main_link, timeout=timeout)
    soup_main = BeautifulSoup(main_page.text, "html.parser")
    book_link = soup_main.find_all('a', id=re.compile('.*recordDisplayLink2.*'), href=True)
    title_list = []
    link_book = []
    isbn_10_lst = []
    for book in book_link:
        title = book.text
        book_link = book['href']
        if title:
            title_list.append(title.strip())
        else:
            title_list.append('')
        if book_link:
            book_link = 'https://browse.nypl.org/'+book_link
            link_book.append(book_link)
            soup_details = requests.get(book_link, timeout=timeout)
            isbn_div = soup_details.find('td', {'class': 'bibInfoData'})[1]
            if (isbn_div):
                isbn_10_lst.append(isbn_div.text.strip())
            else:
                isbn_10_lst.append('')
        else:
            link_book.append('')
        next_link = soup_main.find('a', id=f'.*searchPageLink_{index+1}.*', href=True)['href']
        main_link = 'https://browse.nypl.org/'+next_link
        print(zip(title_list, isbn_10_lst))

# BOOKY SI APPOGGIA SU GOOGLE BOOKS # https://booky-andy.herokuapp.com/query?search=prova