from selenium import webdriver
import time
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
service = Service(executable_path="D:\\chromedriver.exe")
chrome_options = webdriver.ChromeOptions()
# prefs = {"profile.managed_default_content_settings.images": 2}
# chrome_options.add_experimental_option("prefs", prefs)
# chrome_options.add_argument('--headless')
# chrome_options.add_argument('--disable-gpu')
driver = webdriver.Chrome(service=service, options=chrome_options)
driver.maximize_window()
driver.get("https://www.vip.com/")
time.sleep(2)
input_ele = driver.find_element(By.XPATH, '//input[contains(@class, "c-search-input")]')
input_ele.send_keys("风衣")
input_btn = driver.find_element(By.XPATH, '//span[contains(@class, "c-search-icon")]')
input_btn.click()
while True:
time.sleep(3)
try:
iframe = driver.find_element(By.CSS_SELECTOR, '.login_iframe')
driver.switch_to.frame(iframe)
close = driver.find_element(By.CSS_SELECTOR, '.ui-dialog-close')
close.click()
print(f"关闭登录。。。。。。。。。。。")
time.sleep(2)
driver.switch_to.default_content()
time.sleep(2)
except Exception as e:
pass
driver.execute_script("document.documentElement.scrollTop = document.documentElement.scrollHeight")
time.sleep(2)
driver.execute_script("document.documentElement.scrollTop = document.documentElement.scrollHeight")
time.sleep(2)
driver.execute_script("document.documentElement.scrollTop = document.documentElement.scrollHeight")
time.sleep(2)
items = driver.find_elements(By.XPATH, '//section/div[position()>1]')
print(len(items), "==============")
for item in items:
main_img = item.find_element(By.CSS_SELECTOR, '.J-goods-item__img')
# print(main_img.get_attribute("data-original"))
next_page_btn = driver.find_element(By.XPATH, '//*[@id="J_nextPage_link"]')
next_page_btn.click()
time.sleep(5)
driver.quit()
标签:python,selenium,driver,唯品,options,sleep,time,input,find
From: https://blog.csdn.net/zhangzhaoyuxunlei/article/details/143414791