Skip to content Skip to sidebar Skip to footer

Enter Query In Search Bar And Scrape Results

I have a database with ISBN numbers of different books. I gathered them using Python and Beautifulsoup. Next I would like to add categories to the books. There is a standard when i

Solution 1:

You can use selenium to locate the input box and loop over your ISBNs, entering each:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
d = webdriver.Chrome('/path/to/chromedriver')
books = ['9780062457738']
for book in books:
  d.get('https://www.bol.com/nl/')
  e = d.find_element_by_id('searchfor')
  e.send_keys(book)
  e.send_keys(Keys.ENTER)
  #scrape page here 

Now, for each book ISBN in books, the solution will enter the value into the search box and load the desired page.

Solution 2:

You could write a function which returns the category. You can base it on the actual search the page does just tidy up the params and you can use a GET.

import requests
from bs4 import BeautifulSoup as bs

defget_category(isbn): 
    r = requests.get(f'https://www.bol.com/nl/rnwy/search.html?Ntt={isbn}&searchContext=books_all') 
    soup = bs(r.content,'lxml')
    category = soup.select_one('#option_block_4 > li:last-child .breadcrumbs__link-label')

    if category isNone:
        return'Not found'else:
        return category.text

isbns = ['9780141311357', '9780062457738', '9780141199078']

for isbn in isbns:
    print(get_category(isbn))

Post a Comment for "Enter Query In Search Bar And Scrape Results"