Guest User

Zoro.zom

a guest
Aug 27th, 2024
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | Source Code | 0 0
  1. from selenium_driverless import webdriver
  2. from selenium_driverless.types.by import By
  3. import asyncio
  4. import bs4
  5.  
  6.  
  7. async def main():
  8.     options = webdriver.ChromeOptions()
  9.     async with webdriver.Chrome(options=options) as driver:
  10.         await driver.get(url='https://www.zoro.com/search?q=gloves')
  11.  
  12.         cont = input('press enter when site has loaded')
  13.  
  14.         source = await driver.page_source
  15.         soup = bs4.BeautifulSoup(source, 'html.parser')
  16.  
  17.         for product in soup.find_all(name='div', attrs={
  18.             'class': 'product-card search-product-card search-results__item product-card--grid'}):
  19.             img = product.find('img')
  20.             if img:
  21.                 desc = img['alt']
  22.                 if desc:
  23.                     print(f'Product: {desc}')
  24.                 else:
  25.                     print('image found, but no alt desc was found')
  26.             else:
  27.                 print('no image found, bad element?')
  28.  
  29.  
  30. asyncio.run(main())
  31.  
Advertisement
Add Comment
Please, Sign In to add comment