【发布时间】: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