"Message: no such window: target window already closed from unknown error: web view not found"

Question:

I am new to web scraping and here I am trying to extract the product details from a site, there are 48 products on a page, and when I debug I get the length of the list as 48, but I have product details only for 4 products rest of them showing the error. hope someone can help me out.

Thanks in advance

"Message: no such window: target window already closed
from unknown error: web view not found
(Session info: chrome=110.0.5481.177)"

below is my code

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time

DRIVER_PATH = '/home/svc/Downloads/chromedriver_linux64/chromedriver'

options = Options()
options.headless = False
options.add_argument("--window-size=1920,1200")

driver = webdriver.Chrome(options=options, executable_path=DRIVER_PATH)
driver.get("https://www.douglas.at/de/c/koerper/koerperreinigung/duschgel/130101")

time.sleep(1)
all_products = driver.find_element("xpath", "//div[contains(@class, 'product-grid__listing-             content')]")
products = all_products.find_elements('xpath', "//div[contains(@class, 'product-grid-column        col-sm-6 col-md-4 col-lg-3')]")
print("length of the list: ", len(products))
for product in products:
    print("------------------ new product ----------------------------")
    print("productname", "....")
    productname = product.text
    atribute = product.find_element('xpath', "//div[contains(@class, 'text top-brand')]").text
    print(productname)
    print(atribute)

driver.quit()
Asked By: SVC

||

Answers:

Here is a very simple solution even without using selenium.

It scraps all the details of all individual products on the page which holds a total of 48 different products.

Using requests+beautifulsoup

import requests
from bs4 import BeautifulSoup

data = requests.get("https://www.douglas.at/de/c/koerper/koerperreinigung/duschgel/130101")
soup = BeautifulSoup(data.text, 'lxml')
all_products = soup.select('div.product-grid-column.col-sm-6.col-md-4.col-lg-3')
print("length of the list: ", len(all_products))

data = []
for product in all_products:
    product_dict = {
     "product_brand": product.select_one('div.text.top-brand').text,
     "product_name": product.select_one('div.text.name').text,
     "product_category": product.select_one('div.text.category').text,
     "product_price": product.select_one('div.price-row').text.replace('€xa0', ''),
     "product_link": f"'https://www.douglas.at{product.select_one('a').get('href')}"
    }
    try:
        product_line = product.select_one('div.text.brand-line').text
    except AttributeError:
        product_line = None
    product_dict['product_line'] = product_line
    try:
        product_rating = product.select_one('span.ratings-info').text.replace('xa0', '')
    except AttributeError:
        product_rating = None
    product_dict['product_rating'] = product_rating

    data.append(product_dict)

print(data)

output:

length of the list:  48
[{'product_brand': 'Biotherm', 'product_name': 'Set', 'product_category': 'Körperpflegeset', 'product_price': '12,50', 'product_link': "'https://www.douglas.at/de/p/5010891049", 'product_line': 'Eau Pure', 'product_rating': None}, {'product_brand': 'AHAVA', 'product_name': 'Sea-Kissed Mineral Shower Gel', 'product_category': 'Duschgel', 'product_price': '18,99', 'product_link': "'https://www.douglas.at/de/p/m000575223?variant=035126", 'product_line': None, 'product_rating': '5(2)'}, {'product_brand': 'AHAVA', 'product_name': 'Mineral Shower Gel', 'product_category': 'Duschgel', 'product_price': '18,99', 'product_link': "'https://www.douglas.at/de/p/3001007082?variant=016068", 'product_line': None, 'product_rating': '5(3)'}, {'product_brand': 'Aveda', 'product_name': 'Shampure™ Hand & Body Wash', 'product_category': 'Waschlotion', 'product_price': '28,95', 'product_link': "'https://www.douglas.at/de/p/3001046840?variant=028843", 'product_line': 'Aromapflege', 'product_rating': '5(1)'}, {'product_brand': 'Sol de Janeiro', 'product_name': 'Bum Bum Jet Set', 'product_category': 'Körperpflegeset', 'product_price': '27,99', 'product_link': "'https://www.douglas.at/de/p/5010587085", 'product_line': None, 'product_rating': '5(36)'}, {'product_brand': 'Moroccanoil', 'product_name': 'Hand Wash', 'product_category': 'Seife', 'product_price': '22,09', 'product_link': "'https://www.douglas.at/de/p/m001514275?variant=m2695512", 'product_line': None, 'product_rating': None}, {'product_brand': 'NUXE', 'product_name': 'Florale Pflege: Gönnen Sie sich eine blumigen Moment', 'product_category': 'Körperpflegeset', 'product_price': '37,99', 'product_link': "'https://www.douglas.at/de/p/5010778001", 'product_line': 'Huile Prodigieuse®', 'product_rating': '5(2)'}, {'product_brand': "Dr. Bronner's", 'product_name': 'Tea Tree', 'product_category': 'Körperseife', 'product_price': '19,09', 'product_link': "'https://www.douglas.at/de/p/3001008577?variant=848038", 'product_line': None, 'product_rating': '4.5(2)'}, {'product_brand': 'Ziaja', 'product_name': 'Kokosnuss cremiges Duschgel', 'product_category': 'Duschgel', 'product_price': '4,99', 'product_link': "'https://www.douglas.at/de/p/m001241243", 'product_line': None, 'product_rating': None}, {'product_brand': 'Rituals', 'product_name': 'Foaming Shower Gel', 'product_category': 'Duschgel', 'product_price': '9,50', 'product_link': "'https://www.douglas.at/de/p/3000070316?variant=487576", 'product_line': 'The Ritual of Sakura', 'product_rating': '5(10)'}, {'product_brand': 'Sol de Janeiro', 'product_name': 'Brazilian 4 Play™ Moisturizing Shower Cream Gel', 'product_category': 'Duschgel', 'product_price': '48,99', 'product_link': "'https://www.douglas.at/de/p/5010552377?variant=1000692", 'product_line': None, 'product_rating': '5(14)'}, {'product_brand': 'Biotherm', 'product_name': 'Lait de Douche 400ml', 'product_category': 'Duschgel', 'product_price': '25,95', 'product_link': "'https://www.douglas.at/de/p/3000033080", 'product_line': None, 'product_rating': '5(50)'}, {'product_brand': 'Tom Ford', 'product_name': 'Neroli Portofino', 'product_category': 'Duschgel', 'product_price': '77,95', 'product_link': "'https://www.douglas.at/de/p/3000072942", 'product_line': 'Private Blend Düfte', 'product_rating': '5(2)'}, {'product_brand': 'Sol de Janeiro', 'product_name': 'Bom Dia Bright™ Clarifying AHA BHA Body Wash', 'product_category': 'Duschgel', 'product_price': '8,95', 'product_link': "'https://www.douglas.at/de/p/5010895036", 'product_line': None, 'product_rating': '5(2)'}, {'product_brand': 'Biotherm', 'product_name': 'Lait Corporel Verwöhnset', 'product_category': 'Körperpflegeset', 'product_price': '26,29', 'product_link': "'https://www.douglas.at/de/p/5010891042", 'product_line': None, 'product_rating': None}, {'product_brand': 'Biotherm', 'product_name': 'Set', 'product_category': 'Körperpflegeset', 'product_price': '22,49', 'product_link': "'https://www.douglas.at/de/p/5010891048", 'product_line': 'Eau VitaminÉe', 'product_rating': None}, {'product_brand': 'Biotherm', 'product_name': 'Set', 'product_category': 'Körperpflegeset', 'product_price': '56,99', 'product_link': "'https://www.douglas.at/de/p/5010891050", 'product_line': "Eau d'Energie", 'product_rating': None}, {'product_brand': 'Eau My Unicorn', 'product_name': '2 In 1 Shower Gel & Shampoo 3D', 'product_category': 'Duschgel', 'product_price': '16,89', 'product_link': "'https://www.douglas.at/de/p/5010068568", 'product_line': None, 'product_rating': None}, {'product_brand': 'Ziaja', 'product_name': 'Cashmereprotein & Sheabutter cremiges Duschgel', 'product_category': 'Duschgel', 'product_price': '4,99', 'product_link': "'https://www.douglas.at/de/p/m001241248", 'product_line': None, 'product_rating': None}, {'product_brand': 'Sol de Janeiro', 'product_name': 'Brazilian 4 Play  Moisturizing Shower Cream-Gel', 'product_category': 'Duschgel', 'product_price': '24,99', 'product_link': "'https://www.douglas.at/de/p/3001036611", 'product_line': None, 'product_rating': '4.5(61)'}, {'product_brand': 'Dolce&Gabbana', 'product_name': 'Shower Gel', 'product_category': 'Duschgel', 'product_price': '36,29', 'product_link': "'https://www.douglas.at/de/p/3011043774", 'product_line': 'K by Dolce&Gabbana', 'product_rating': '5(2)'}, {'product_brand': 'Narciso Rodriguez', 'product_name': '', 'product_category': 'Duftset', 'product_price': '88,99', 'product_link': "'https://www.douglas.at/de/p/5010718132", 'product_line': 'for her', 'product_rating': None}, {'product_brand': 'Molton Brown', 'product_name': 'Orange & Bergamot Body Wash', 'product_category': 'Duschgel', 'product_price': '29,95', 'product_link': "'https://www.douglas.at/de/p/3001043028", 'product_line': 'Body Essentials', 'product_rating': '5(10)'}, {'product_brand': 'Narciso Rodriguez', 'product_name': 'POUDRÉE', 'product_category': 'Duftset', 'product_price': '88,99', 'product_link': "'https://www.douglas.at/de/p/5010718138", 'product_line': 'Narciso', 'product_rating': None}, {'product_brand': 'Molton Brown', 'product_name': 'Re-charge Black Pepper Bath & Shower Gel', 'product_category': 'Duschgel', 'product_price': '28,95', 'product_link': "'https://www.douglas.at/de/p/3001041278", 'product_line': 'Body Essentials', 'product_rating': '5(10)'}, {'product_brand': 'Ziaja', 'product_name': 'Arganöl cremiges Duschgel', 'product_category': 'Duschgel', 'product_price': '4,99', 'product_link': "'https://www.douglas.at/de/p/m001241242", 'product_line': None, 'product_rating': None}, {'product_brand': 'Speick Naturkosmetik', 'product_name': 'Natural - Deo Dusch Hair - Body 5L', 'product_category': 'Duschgel', 'product_price': '70,89', 'product_link': "'https://www.douglas.at/de/p/m000004037", 'product_line': None, 'product_rating': None}, {'product_brand': 'Roger & Gallet', 'product_name': 'Shower Gel', 'product_category': 'Duschgel', 'product_price': '18,89', 'product_link': "'https://www.douglas.at/de/p/5010845072", 'product_line': 'Rose', 'product_rating': '5(1)'}, {'product_brand': 'Molton Brown', 'product_name': 'Coastal Cypress & Sea Fennel Bath & Shower Gel', 'product_category': 'Duschgel', 'product_price': '28,95', 'product_link': "'https://www.douglas.at/de/p/5010478110", 'product_line': 'Body Essentials', 'product_rating': '4.5(9)'}, {'product_brand': 'Juliette Has a Gun', 'product_name': 'Not a Shower Gel', 'product_category': 'Duschgel', 'product_price': '29,99', 'product_link': "'https://www.douglas.at/de/p/5010238071", 'product_line': None, 'product_rating': '5(2)'}, {'product_brand': '', 'product_name': 'Wild Lemongrass - Body Wash', 'product_category': 'Duschgel', 'product_price': '14,19', 'product_link': "'https://www.douglas.at/de/p/m001559004", 'product_line': None, 'product_rating': None}, {'product_brand': '', 'product_name': 'Fragrance Free - Body Wash', 'product_category': 'Duschgel', 'product_price': '14,19', 'product_link': "'https://www.douglas.at/de/p/m001559000", 'product_line': None, 'product_rating': None}, {'product_brand': 'Biotherm', 'product_name': 'Set', 'product_category': 'Körperpflegeset', 'product_price': '56,95', 'product_link': "'https://www.douglas.at/de/p/5010891045", 'product_line': 'Eau Pure', 'product_rating': None}, {'product_brand': 'Biotherm', 'product_name': 'Set', 'product_category': 'Körperpflegeset', 'product_price': '68,89', 'product_link': "'https://www.douglas.at/de/p/5010891046", 'product_line': 'Eau VitaminÉe', 'product_rating': None}, {'product_brand': 'Ben & Anna', 'product_name': '', 'product_category': 'Duschgel', 'product_price': '8,89', 'product_link': "'https://www.douglas.at/de/p/5010709006", 'product_line': None, 'product_rating': None}, {'product_brand': 'Ben & Anna', 'product_name': '', 'product_category': 'Duschgel', 'product_price': '11,79', 'product_link': "'https://www.douglas.at/de/p/5010661007", 'product_line': None, 'product_rating': None}, {'product_brand': '', 'product_name': 'Duschgel', 'product_category': 'Duschgel', 'product_price': '16,99', 'product_link': "'https://www.douglas.at/de/p/5010438009", 'product_line': None, 'product_rating': None}, {'product_brand': 'Grace Cole', 'product_name': '', 'product_category': 'Duschgel', 'product_price': '8,99', 'product_link': "'https://www.douglas.at/de/p/5010079436", 'product_line': None, 'product_rating': None}, {'product_brand': 'Guerlain', 'product_name': 'Bergamote', 'product_category': 'Duschgel', 'product_price': '48,99', 'product_link': "'https://www.douglas.at/de/p/5002487005", 'product_line': 'Aqua Allegoria', 'product_rating': None}, {'product_brand': 'Rituals', 'product_name': 'Foaming Shower Gel', 'product_category': 'Duschgel', 'product_price': '9,95', 'product_link': "'https://www.douglas.at/de/p/5009749020?variant=487789", 'product_line': 'The Ritual of Jing', 'product_rating': None}, {'product_brand': 'Sóley Organics', 'product_name': 'Blaer Shower Gel', 'product_category': 'Duschgel', 'product_price': '39,99', 'product_link': "'https://www.douglas.at/de/p/m001057468", 'product_line': None, 'product_rating': None}, {'product_brand': 'Ziaja', 'product_name': 'Olivenöl pflegendes Duschgel', 'product_category': 'Duschgel', 'product_price': '4,99', 'product_link': "'https://www.douglas.at/de/p/m001308026", 'product_line': None, 'product_rating': '5(1)'}, {'product_brand': 'Issey Miyake', 'product_name': 'Shower Cream', 'product_category': 'Duschgel', 'product_price': '39,95', 'product_link': "'https://www.douglas.at/de/p/5009896001", 'product_line': "A Drop d'Issey", 'product_rating': None}, {'product_brand': 'JOOP!', 'product_name': '', 'product_category': 'Duschgel', 'product_price': '15,39', 'product_link': "'https://www.douglas.at/de/p/3000002432", 'product_line': 'JOOP! Homme', 'product_rating': '5(39)'}, {'product_brand': 'Acqua del Garda', 'product_name': '', 'product_category': 'Duschgel', 'product_price': '16,99', 'product_link': "'https://www.douglas.at/de/p/5010540016", 'product_line': None, 'product_rating': None}, {'product_brand': 'Acqua del Garda', 'product_name': '', 'product_category': 'Duschgel', 'product_price': '16,99', 'product_link': "'https://www.douglas.at/de/p/5010540015", 'product_line': None, 'product_rating': None}, {'product_brand': 'Madara', 'product_name': 'Bitter Honey Moisture Wash', 'product_category': 'Duschgel', 'product_price': '18,99', 'product_link': "'https://www.douglas.at/de/p/5010803014", 'product_line': None, 'product_rating': None}, {'product_brand': 'DeclarÉ', 'product_name': '', 'product_category': 'Duschgel', 'product_price': '16,95', 'product_link': "'https://www.douglas.at/de/p/3000001817", 'product_line': 'Body Care', 'product_rating': '4.5(14)'}]

as you can see, the variable ‘data‘ contains all 48 products with all of their details.

I hope you like this simple solution.

Answered By: Ajeet Verma