Esempio n. 1
0
def nest_page(driver):
    '''处理嵌套页面的情况:页面内又含有分支页面'''
    print 'in nest_page'
    global Depth
    if Depth <= 1:  # 深度最多为1层
        try:
            driver.find_element_by_class_name('pro_list_pic')
        except NoSuchElementException:
            Depth += 1
            print 'need to jump again'
            eles = driver.find_elements_by_tag_name('a')
            pattern = re.compile('show-\d+.html$')
            for ele in eles:
                if pattern.search(str(ele.get_attribute('href'))):
                    print 'before click'
                    action = ActionChains(driver)
                    action.click(ele).perform()
                    print 'after click'
                    # 切换到新的窗口
                    base_page = ele.get_attribute('href')
                    print 'go into ' + base_page
                    try:
                        driver.current_url
                    except:
                        pass
                    page.switch_do(driver, process, base_page)
            Depth -= 1
            return
Esempio n. 2
0
def nest_page(driver):
    '''处理嵌套页面的情况:页面内又含有分支页面'''
    print 'in nest_page'
    global Depth
    if Depth <= 1:  # 深度最多为1层
        try:
            driver.find_element_by_class_name('pro_list_pic')
        except NoSuchElementException:
            Depth += 1
            print 'need to jump again'
            eles = driver.find_elements_by_tag_name('a')
            pattern = re.compile('show-\d+.html$')
            for ele in eles:
                if pattern.search(str(ele.get_attribute('href'))):
                    print 'before click'
                    action = ActionChains(driver)
                    action.click(ele).perform()
                    print 'after click'
                    # 切换到新的窗口
                    base_page = ele.get_attribute('href')
                    print 'go into ' + base_page
                    try:
                        driver.current_url
                    except:
                        pass
                    page.switch_do(driver, process, base_page)
            Depth -= 1
            return
Esempio n. 3
0
def search_brand(item, name):
    '''搜需要的品牌'''
    print 'in search_brand',item,name
    try:  # 如果找不到,就直接return
        lis = driver.find_elements_by_class_name(item)
    except:
        print platfm.local_str('没有' + item + '条目,返回')
        return
    print 'after find'
    # driver.set_page_load_timeout(0.5) #0.5s超时,太短的话(0.1s)click可能会超时
    driver.set_page_load_timeout(4)  # 等待嵌套页面加载需要的时间较长
    for li in lis:
        info = li.find_element_by_class_name(name).text
        print info
        # 至少包括Brands里的一项,包括Keys里的所有项
        if (filter(lambda x: x.lower() in info.lower(), Brands) and
                (Keys and Keys == filter(lambda x: x.lower() in info.lower(),
                 Keys) or not Keys)):
            global MixFlag
            if u"男女" in info:
                MixFlag = True
            action = ActionChains(driver)
            action.click(li).perform()
            print 'after click'
            time.sleep(5)
            print 'after sleep'
            # 切换到新的窗口
            print 'go into ' + info
            page.switch_do(driver, process)
            MixFlag = False
Esempio n. 4
0
def search_brand(item, name):
    '''搜需要的品牌'''
    print 'in search_brand', item, name
    try:  # 如果找不到,就直接return
        lis = driver.find_elements_by_class_name(item)
    except:
        print platfm.local_str('没有' + item + '条目,返回')
        return
    print 'after find'
    # driver.set_page_load_timeout(0.5) #0.5s超时,太短的话(0.1s)click可能会超时
    driver.set_page_load_timeout(4)  # 等待嵌套页面加载需要的时间较长
    for li in lis:
        info = li.find_element_by_class_name(name).text
        print info
        # 至少包括Brands里的一项,包括Keys里的所有项
        if (filter(lambda x: x.lower() in info.lower(), Brands) and
            (Keys and Keys == filter(lambda x: x.lower() in info.lower(), Keys)
             or not Keys)):
            global MixFlag
            if u"男女" in info:
                MixFlag = True
            action = ActionChains(driver)
            action.click(li).perform()
            print 'after click'
            time.sleep(5)
            print 'after sleep'
            # 切换到新的窗口
            print 'go into ' + info
            page.switch_do(driver, process)
            MixFlag = False