【问题标题】:scraping amazon deals page 40 product but get 15 product抓取亚马逊交易第 40 页产品但获得 15 个产品
【发布时间】:2020-03-18 16:36:18
【问题描述】:

我想从亚马逊的交易页面抓取所有产品(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()

【问题讨论】:

    标签: python selenium web-scraping beautifulsoup


    【解决方案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']")
    

    截图:

    【讨论】:

    • show 是什么意思?当你想基于 css 选择项目时,你可以使用soup.select
    • 我英文不好(我指的是截图中你在图片底部提到的部分)
    • 查看this 的帖子。而不是使用 xpath,您可以尝试使用上面屏幕截图中提到的 css。
    猜你喜欢
    • 1970-01-01
    • 2019-08-11
    • 2015-11-03
    • 1970-01-01
    • 2017-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多