【问题标题】:trying to scroll to bottom of popup page window试图滚动到弹出页面窗口的底部
【发布时间】:2020-10-22 14:43:38
【问题描述】:

我正在尝试滚动到 Stockx 弹出页面的底部,以收集某件商品的所有近期销售价格。 但我似乎无法到达弹出窗口的底部以单击加载更多按钮。 这就是我到目前为止所拥有的。请帮忙。

import bs4 
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys 

PATH = "C:\Program Files (x86)\chromedriver.exe"

driver = webdriver.Chrome(PATH)
driver.get("https://stockx.com/supreme-patchwork-mohair-cardigan-multicolor")
time.sleep(3)
driver.find_element_by_xpath('//*[@id="root"]/div[1]/div[2]/div[2]/div[9]/div/div/div/div[2]/div/div[2]/div/div/button').click()
driver.find_element_by_xpath('//*[@id="root"]/div[1]/div[2]/div[2]/div[9]/div/div/div/div[2]/div/div[1]/div[2]/a').click()
time.sleep(3)
element_in_popup = driver.find_element_by_xpath('/html/body/div[9]/div/div/div/div[2]/div')
while EC.presence_of_element_located((By.XPATH,'/html/body/div[9]/div/div/div/div[2]/div/button')):
    element_in_popup.send_keys(Keys.END) # Use send_keys(Keys.HOME) to scroll up to the top of page
    driver.find_element_by_xpath('/html/body/div[9]/div/div/div/div[2]/div/button').click()
    

【问题讨论】:

标签: python selenium web-scraping popup window


【解决方案1】:

我能够使用按钮的 css 选择器与弹出模式交互以加载更多结果。

【讨论】:

    【解决方案2】:

    您可以获取带有 xpath 的按钮并尽可能多地单击它。这是我用来执行此操作的代码:

        from selenium import webdriver
        import time
    
        driver = webdriver.Chrome()
        driver.get("https://stockx.com/supreme-patchwork-mohair-cardigan-multicolor")
        time.sleep(2)
    
        confirm_location_btn = driver.find_element_by_xpath('//*[@id="root"]/div[1]/div[2]/section/div/div[2]/button')
        confirm_location_btn.click()
        time.sleep(2)
    
        okay_cookies_btn = driver.find_element_by_xpath('//*[@id="root"]/div[2]/div[2]/button')
        okay_cookies_btn.click()
        time.sleep(2)
    
        view_all_sales_btn = driver.find_element_by_xpath('//*[@id="Supreme Patchwork Mohair Cardigan Multicolor"]/div[2]/div[3]/a')
        view_all_sales_btn.click()
        time.sleep(2)
    
        thanks_btn = driver.find_element_by_xpath('/html/body/div[7]/div/div/div/div[2]/div/div[1]/div/button')
        thanks_btn.click()
        time.sleep(2)
    
        load_more_btn = driver.find_element_by_xpath('/html/body/div[7]/div/div/div/div[2]/div/button')
        load_more_btn.click()
        time.sleep(2)
        load_more_btn.click()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-16
      相关资源
      最近更新 更多