I believe you can use the following code as a guideline. In this code, all rows are expanded, and the product link is accessed to retrieve the corresponding description. This process is repeated for all rows in the tables. The requested information is printed in a simple format; however, you can use libraries like pandas or others to give a more structured format to the extracted data.
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
options = webdriver.ChromeOptions()
options.add_experimental_option("detach", True)
driver = webdriver.Chrome(options=options)
website = 'https://www.grainger.com/category/adhesives-sealants-and-tape/patching-repairing-compounds/wall-repair-patching?categoryIndex=2'
driver.get(website)
tables = driver.find_elements(By.XPATH, '//tbody[@class="cjpIYY"]')
for i in range(len(tables)):
table = driver.find_elements(By.XPATH, '//tbody[@class="cjpIYY"]')[i]
rows = table.find_elements(By.CLASS_NAME, '-dql2z')
j = 0
for j in range(len(rows)):
# update references
table = driver.find_elements(By.XPATH, '//tbody[@class="cjpIYY"]')[i]
row = table.find_elements(By.CLASS_NAME, '-dql2z')[j]
row.click()
# to load the expanded information of the row
time.sleep(1)
# product page link
product_page = driver.find_element(By.XPATH, '//a[@class="JEyT-B _3ihaM4"]')
product_page.click()
time.sleep(2)
# Extract data
print("Mfr. model: %s" % driver.find_element(By.XPATH, '//div[@class="vDgTDH"][2]/dd').text)
print("Price: %s" % driver.find_element(By.XPATH, '//span[@class="rbqU0E lVwVq5"]').text)
print("Description: %s" % driver.find_element(By.XPATH, '//dd[@class="W7BBCC"]/p').text)
driver.back()
print()
j += 1
print()
i += 1
And the output is this:
Mfr. model: 52084
Price: $9.83
Description: Joint compounds and plaster spread along drywall panel seams, nail heads, and indentions to create a smooth finish to the wall surface. Also called mud, joint compounds are typically used in conjunction with mesh drywall patches and tape. Once dried, these compounds are sandable in preparation for texturing, painting and other finishing applications.
Mfr. model: 10100
Price: $9.22
Description: Joint compounds and plaster spread along drywall panel seams, nail heads, and indentions to create a smooth finish to the wall surface. Also called mud, joint compounds are typically used in conjunction with mesh drywall patches and tape. Once dried, these compounds are sandable in preparation for texturing, painting and other finishing applications.
Mfr. model: 10308
Price: $8.86
Description: Joint compounds and plaster spread along drywall panel seams, nail heads, and indentions to create a smooth finish to the wall surface. Also called mud, joint compounds are typically used in conjunction with mesh drywall patches and tape. Once dried, these compounds are sandable in preparation for texturing, painting and other finishing applications.
Mfr. model: 58550
Price: $11.80
Description: Joint compounds and plaster spread along drywall panel seams, nail heads, and indentions to create a smooth finish to the wall surface. Also called mud, joint compounds are typically used in conjunction with mesh drywall patches and tape. Once dried, these compounds are sandable in preparation for texturing, painting and other finishing applications.
Mfr. model: 10310
Price: $16.68
Description: Joint compounds and plaster spread along drywall panel seams, nail heads, and indentions to create a smooth finish to the wall surface. Also called mud, joint compounds are typically used in conjunction with mesh drywall patches and tape. Once dried, these compounds are sandable in preparation for texturing, painting and other finishing applications.
Mfr. model: 58555
Price: $26.91
Description: Joint compounds and plaster spread along drywall panel seams, nail heads, and indentions to create a smooth finish to the wall surface. Also called mud, joint compounds are typically used in conjunction with mesh drywall patches and tape. Once dried, these compounds are sandable in preparation for texturing, painting and other finishing applications.
Mfr. model: 10114
Price: $17.94
Description: Joint compounds and plaster spread along drywall panel seams, nail heads, and indentions to create a smooth finish to the wall surface. Also called mud, joint compounds are typically used in conjunction with mesh drywall patches and tape. Once dried, these compounds are sandable in preparation for texturing, painting and other finishing applications.
Mfr. model: 60590
Price: $40.49
Description: Joint compounds and plaster spread along drywall panel seams, nail heads, and indentions to create a smooth finish to the wall surface. Also called mud, joint compounds are typically used in conjunction with mesh drywall patches and tape. Once dried, these compounds are sandable in preparation for texturing, painting and other finishing applications.
Mfr. model: 10120
Price: $27.43
Description: Joint compounds and plaster spread along drywall panel seams, nail heads, and indentions to create a smooth finish to the wall surface. Also called mud, joint compounds are typically used in conjunction with mesh drywall patches and tape. Once dried, these compounds are sandable in preparation for texturing, painting and other finishing applications.
Mfr. model: 18746
Price: $14.09
Description: Spackling paste, also called painter's putty and spackle, is used to fill minor imperfections in wall surfaces such as nail holes, dents, and divots. It is fast drying, does not require sanding, and is primarily used in preparation for painting.
Mfr. model: 12330
Price: $12.80
Description: Spackling paste, also called painter's putty and spackle, is used to fill minor imperfections in wall surfaces such as nail holes, dents, and divots. It is fast drying, does not require sanding, and is primarily used in preparation for painting.
Mfr. model: 12288
Price: $18.94
Description: Spackling paste, also called painter's putty and spackle, is used to fill minor imperfections in wall surfaces such as nail holes, dents, and divots. It is fast drying, does not require sanding, and is primarily used in preparation for painting.
Mfr. model: 12278
Price: $18.96
Description: Spackling paste, also called painter's putty and spackle, is used to fill minor imperfections in wall surfaces such as nail holes, dents, and divots. It is fast drying, does not require sanding, and is primarily used in preparation for painting.
Mfr. model: 12142
Price: $12.91
Description: Spackling paste, also called painter's putty and spackle, is used to fill minor imperfections in wall surfaces such as nail holes, dents, and divots. It is fast drying, does not require sanding, and is primarily used in preparation for painting.
Mfr. model: 12132
Price: $10.53
Description: Spackling paste, also called painter's putty and spackle, is used to fill minor imperfections in wall surfaces such as nail holes, dents, and divots. It is fast drying, does not require sanding, and is primarily used in preparation for painting.
Mfr. model: 09903
Price: $4.76
Description: Drywall patches and tape adhere to drywall to cover and bond panel joints and cover larger holes or cracks. They are typically mesh and are used in conjunction with joint compounds to create a smooth finish to the wall surface.
Mfr. model: 09904
Price: $5.66
Description: Drywall patches and tape adhere to drywall to cover and bond panel joints and cover larger holes or cracks. They are typically mesh and are used in conjunction with joint compounds to create a smooth finish to the wall surface.
Mfr. model: 2297
Price: $8.43
Description: Drywall patches and tape adhere to drywall to cover and bond panel joints and cover larger holes or cracks. They are typically mesh and are used in conjunction with joint compounds to create a smooth finish to the wall surface.
Mfr. model: 09007
Price: $8.05
Description: Drywall patches and tape adhere to drywall to cover and bond panel joints and cover larger holes or cracks. They are typically mesh and are used in conjunction with joint compounds to create a smooth finish to the wall surface.
Mfr. model: MJ 100
Price: $10.36
Description: Drywall patches and tape adhere to drywall to cover and bond panel joints and cover larger holes or cracks. They are typically mesh and are used in conjunction with joint compounds to create a smooth finish to the wall surface.
Mfr. model: 13A758
Price: $6.01
Description: Drywall patches and tape adhere to drywall to cover and bond panel joints and cover larger holes or cracks. They are typically mesh and are used in conjunction with joint compounds to create a smooth finish to the wall surface.
Mfr. model: 13A757
Price: $12.50
Description: Drywall patches and tape adhere to drywall to cover and bond panel joints and cover larger holes or cracks. They are typically mesh and are used in conjunction with joint compounds to create a smooth finish to the wall surface.
In my opinion, in this particular case, it would be more beneficial to use a tool like scrapy. This is a tool that I often use in my work, and it has proven to be helpful. It is essential to consider that, depending on the problem you face, one tool may be more suitable than another.
Also, I would like to recommend that you expand your knowledge of selectors for the data extraction process web scraping. In the provided example, the XPATH selector is used as it is the one I find most comfortable; however, you can choose whichever selector you prefer and best suits your needs.