Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Selenium正在浏览程序,而不是等待数据出现_Python_Selenium_For Loop_Range_Wait - Fatal编程技术网

Python Selenium正在浏览程序,而不是等待数据出现

Python Selenium正在浏览程序,而不是等待数据出现,python,selenium,for-loop,range,wait,Python,Selenium,For Loop,Range,Wait,无论我做了什么样的等待,EC,睡眠,我都无法让它慢到足以登记我的库存 出现的问题是脚本执行99的输入。然后,在库存可以注册之前,它跳回L或LORGE。所以它变大了,零件变大了,然后变大了1倍,在它可以注册库存之前,它变大了,然后变大了2倍,在它可以注册发明家之前,它又变大了,然后继续变大了3倍 import selenium from selenium import webdriver from selenium.webdriver.common.keys import Keys from

无论我做了什么样的等待,EC,睡眠,我都无法让它慢到足以登记我的库存

出现的问题是脚本执行99的输入。然后,在库存可以注册之前,它跳回L或LORGE。所以它变大了,零件变大了,然后变大了1倍,在它可以注册库存之前,它变大了,然后变大了2倍,在它可以注册发明家之前,它又变大了,然后继续变大了3倍

import selenium

from selenium import webdriver

from selenium.webdriver.common.keys import Keys

from selenium.webdriver.common.by import By

from selenium.webdriver.support.ui import WebDriverWait

from selenium.webdriver.support import expected_conditions as EC

from selenium.webdriver.common.action_chains import ActionChains

from lxml import html

from time import sleep

import time

import csv

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

driver = webdriver.Chrome(PATH)

driver.get('https://www.rosegal.com/plus-size-tops-120/')

driver.maximize_window()

# This is for pagination.
for x in range(1, 60)

    # This is for the rows the produt is on.
    for r in range(1, 15):
        
        # This is for the product it's on the rows.
        for m in range(1,4):
            sleep(2) 
            # This resets the page of products   
            driver.get(f"https://www.rosegal.com/plus-size-tops-120/{x}.html")
            a = ActionChains(driver)
            product = driver.find_element_by_xpath(f'/html[1]/body[1]/div[1]/div[1]/div[1]/div[2]/div[2]/div[5]/ul[{r}]/li[{m}]/div[1]/div[2]/p[1]/a[1]')
            a.move_to_element(product ).click().perform()
            sleep(1)
            title= driver.find_element_by_xpath("/html[1]/body[1]/div[1]/section[1]/div[1]/div[2]/div[1]/h1[1]").text
            price= driver.find_element_by_xpath("//b[contains(@class,'my_shop_price')]").text
            # This clicks the decscription button that causes the description list to show.
            description= driver.find_element_by_xpath('//*[@id="page"]/section/div/div[2]/div[9]/ul/li[2]').click()
            sleep(2)
            material= driver.find_element_by_xpath("//div[contains(@class,'xxkkk20')]").text

            # This controls the color choice. There could be 1 to 5 colors for a product
            for c in range(1, 5):
                # Since there could be 1 to 5 colors to chose from this try is a simple way the do the colors.
                try:
                    
                    # This calls up the different colors.
                    pat1= driver.find_element_by_xpath(f'//*[@id="select-attr-0"]/a[{c}]').click()
                    color1 = driver.find_element_by_css_selector(".logsss_event_cl.itemAttr.current").get_attribute("data-value")
                    #link = driver.find_element_by_css_selector(".logsss_event_cl.itemAttr.current>img").get_attribute("src")
                    print(color1)
                    
                    # This for s selects the SIZE.
                    for s in range(1, 8):
                        
                        # Since there could be 6 to 8 sizes this try checks for them.
                        try:
                            
                            # This calls up the different sizes.              
                            Size_button = driver.find_element_by_xpath(f'//*[@id="select-attr-1"]/span[2]/a[{s}]').click()
                            
                            image4 = driver.find_element_by_xpath('//*[@id="goods_thumb_content"]/ul/li[1]').get_attribute("data-bigimg")
                            image4 = driver.find_element_by_xpath('//*[@id="goods_thumb_content"]/ul/li[2]').get_attribute("data-bigimg")
                            image4 = driver.find_element_by_xpath('//*[@id="goods_thumb_content"]/ul/li[3]').get_attribute("data-bigimg")
                            
                            # Since there can be a forth image, this try takes care of this.
                            try:
                                image4 = driver.find_element_by_xpath('//*[@id="goods_thumb_content"]/ul/li[4]').get_attribute("data-bigimg")
                            except:
                                pass
                            size = driver.find_element_by_xpath(f'//body[1]/div[1]/section[1]/div[1]/div[2]/div[7]/span[2]/a[{s}]').text  
                            sku = driver.find_element_by_xpath('//*[@id="js_addToCart"]').get_attribute("data-goods-sn")
                            
                            ####### This where the problem startsdatetime #######
                            
                            # First you put in a high number in the QTY input box.                
                            input = driver.find_element_by_xpath("//input[contains(@class,'fl num logsss_event_cl')]").send_keys('99')
                            
                            #Then you hit the Plus sign.
                            plus = driver.find_element_by_xpath('//*[@id="select-attr-1"]/span[2]/a[1]').click()
                            sleep(8)
    
                            # Then the true inventory shows up.
                            inventory = driver.find_element_by_xpath("//input[contains(@class,'fl num logsss_event_cl')]"). get_attribute("value")
                            
                            ##### The problem happens is the script does the input of 99. Then it skip back to L or large before the inventory can register
                            ##### So it goes to Large finishes that part then goes to 1X then before it can register the inventpry it's goes back to Large, then to 
                            ##### 2X and again before it can register the inventor it goes back to Large again before it continues to 3x.
                            sleep(8)
                            print(sku,  size, inventory)    
                        
                            
                        except:
                            pass
                        
                except:
                    pass

我做了所有的尝试:除了:从那一部分中,睡眠起了作用。显然是睡觉,然后尝试:不要一起去


感谢您的帮助

很抱歉,我无法使代码正常运行。在您获得SKU变量后,是否添加了隐式等待?因为你的代码没有显示你添加的等待。是的,我尝试了隐式等待,期望等待,我甚至编造了一些。什么都没用。给我一个试试,我很乐意。我一辈子都不明白为什么每次都会变大。我已经用了很多的靶场,这是我第一次让它这样做。我的逻辑不正确吗?当你添加隐式等待时,你等待了多少秒?我会使用8到30秒,我甚至尝试了40秒。