抓取亚马逊交易第40页的产品,但获得15个产品

时间:2020-03-18 16:36:18

标签: python selenium web-scraping beautifulsoup

我想在亚马逊的交易页面中废弃所有产品(40),但只得到16个产品,我进行了很多搜索,发现我应该使用滚动条,但是我得到了相同的值,但是滚动条不起作用

代码

# -*- coding: utf-8 -*-
import requests
import time
from bs4 import BeautifulSoup
from selenium import webdriver
driver = webdriver.Chrome(executable_path='C:\\Users\\Compu City\\Desktop\\chromedriver.exe')

driver.get('https://www.amazon.com/international-sales-offers/b/?ie=UTF8&node=15529609011&ref_=nav_navm_intl_deal_btn')
time.sleep(10)
res = driver.execute_script("return document.documentElement.outerHTML",'window.scrollBy(0,2000)')
soup = BeautifulSoup(res , 'lxml')
for x in soup.find_all('a',{'class':'a-size-base a-link-normal dealTitleTwoLine singleCellTitle autoHeight'}):
    for y in x.find_all('span',{'class':'a-declarative'}):
        print('\n >>>'+y.text+'\n')
driver.close()

1 个答案:

答案 0 :(得分:1)

您可以使用下面的CSS获取全部40个项目。

div[class^='a-section a-spacing-none tallCellView gridColumn']
# below is the line to get all the products
soup.select("div[class^='a-section a-spacing-none tallCellView gridColumn']")

截屏:

enter image description here