我没有得到所有的链接,这些页面中有403 links
,我只得到了68 links
,我还使用了向下滚动的方法,他们移动到页面末尾,但没有给出所有链接,如果我做错了什么,请引导我们这些是页面链接https://www.ocado.com/search?entry=frozen
from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support.select import Select
from selenium.webdriver.support import expected_conditions as EC
import pandas as pd
url='https://www.ocado.com/search?entry=frozen'
PATH="C:\Program Files (x86)\chromedriver.exe"
driver =webdriver.Chrome(PATH)
driver.get(url)
SCROLL_PAUSE_TIME = 50
last_height = driver.execute_script("return document.body.scrollHeight")
while True:
# Scroll down to bottom
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
# Wait to load page
time.sleep(SCROLL_PAUSE_TIME)
# Calculate new scroll height and compare with last scroll height
new_height = driver.execute_script("return document.body.scrollHeight")
if new_height == last_height:
break
last_height = new_height
t=driver.find_elements(By.XPATH, "//div[@class='fop-contentWrapper']")
for l in t:
links= l.find_element(By.XPATH, ".//a[starts-with(@href, '/products')]").get_attribute("href")
print(links)
1条答案
按热度按时间kh212irz1#
有了这些,应该就足够了:
实际上每页有403个产品