selenium webdriver - Count Images on Amazon Product Detail Page Python -


im new coding python. please bear me im trying find number of product images product has on amazon. 1. cant seem work correctly? 2. there way insert list of asins can print out number? thanks!

import bs4  import webbrowser  import requests  file = requests.get('https://www.amazon.com/dp/b01mrxqpj5')  soup = bs4.beautifulsoup(file.text, 'html.parser' )  elems = soup.select('ul.a-unordered-list a-nostyle a-button-list a-vertical a-spacing-top-micro > li ')

since amazon render it's page using javascript, content generated @ client side, instead of server-side.

when use requests content @ server-side. content generated in client-side, must use selenium or dryscrape, example.

here's working code count number of items list of product ids.

code:

import selenium.webdriver webdriver import lxml.html html import lxml.html.clean clean  urls = ['b017tspk5k', 'b00b96klcq', 'b01mz9e6cg']  browser = webdriver.chrome()  url in urls:     amazon_url = "https://www.amazon.com/dp/{}".format(url)      browser.get(amazon_url)     content = browser.page_source      cleaner = clean.cleaner()     content = cleaner.clean_html(content)     doc = html.fromstring(content)     soup = beautifulsoup(content, 'html.parser')      soup_li = soup.find_all('li', {'class':'a-spacing-small item a-declarative'})      print("product id: {} has {} images.".format(url, len(soup_li)))  browser.close() 

output:

'product id: b017tspk5k has 2 images.' 'product id: b00b96klcq has 5 images.' 'product id: b01mz9e6cg has 3 images.' 

Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -