Exemplo n.º 1
0
def process(driver, base_page):
    '''处理每一个品牌'''
    # 暂时不处理嵌套页面
    # nest_page(driver)  # 嵌套页面
    print 'process begins...'
    sizeIdx = -1
    for type, size in zip(Type, Size):
        print type, size
        has_more = True
        num = 1
        sizeIdx += 1
        while has_more:
            # 加载新页
            new_url = base_page + \
                "?q=0|%s|%s|%s|%s|%d" % (
                    TYPE[type],
                    SIZE[size.lower()],
                    EMPTY[Empty],
                    SORT[Sort],
                    num)
            print new_url
            driver.set_page_load_timeout(3)  # 3s超时
            page.call_ignore(driver.get, new_url)
            num += 1
            print 'after get the page'
            # 判断是否存在
            try:
                driver.find_element_by_class_name('pro_find_none')
            except NoSuchElementException:
                pass
            else:
                print platfm.local_str('不存在该类别的商品')
                break
            # 判断是否是最后一页
            try:
                attr = driver.find_element_by_class_name(
                    'page_next').get_attribute(
                    'href')
                if not attr:
                    has_more = False
            except:
                has_more = False
            print 'before control'
            control(driver, str(sizeIdx))
            print 'after control'
    print 'process ends...'
Exemplo n.º 2
0
def process(driver, base_page):
    '''处理每一个品牌'''
    # 暂时不处理嵌套页面
    # nest_page(driver)  # 嵌套页面
    print 'process begins...'
    sizeIdx = -1
    for type, size in zip(Type, Size):
        print type, size
        has_more = True
        num = 1
        sizeIdx += 1
        while has_more:
            # 加载新页
            new_url = base_page + \
                "?q=0|%s|%s|%s|%s|%d" % (
                    TYPE[type],
                    SIZE[size.lower()],
                    EMPTY[Empty],
                    SORT[Sort],
                    num)
            print new_url
            driver.set_page_load_timeout(3)  # 3s超时
            page.call_ignore(driver.get, new_url)
            num += 1
            print 'after get the page'
            # 判断是否存在
            try:
                driver.find_element_by_class_name('pro_find_none')
            except NoSuchElementException:
                pass
            else:
                print platfm.local_str('不存在该类别的商品')
                break
            # 判断是否是最后一页
            try:
                attr = driver.find_element_by_class_name(
                    'page_next').get_attribute('href')
                if not attr:
                    has_more = False
            except:
                has_more = False
            print 'before control'
            control(driver, str(sizeIdx))
            print 'after control'
    print 'process ends...'
Exemplo n.º 3
0
            page.switch_do(driver, process)
            MixFlag = False


if __name__ == '__main__':
    try:
        platfm.init()
        proc.forks()
        print 'after forks'

        driver = webdriver.Chrome()
        driver.set_window_position(0, 0)
        driver.set_window_size(ScreenW, ScreenH1)

        # platfm.first_timeout(driver)
        page.call_ignore(driver.get, HomeUrl)
        print 'after get the homepage'

        if TestMode:
            # 如果不执行wait_for_begin,就必须刷新一次,否则选地址的div挡着没法点击链接
            print 'TestMode'
            xpath="//div[@class='area_choose']/dl[3]/dd/a[7]"
            ele=WebDriverWait(driver,30).until(EC.element_to_be_clickable((By.XPATH,xpath)))
            print 'before click'
            ele.click() # 选择地区
        else:
            print 'Non-TestMode'
            page.wait_for_begin(driver)
            print 'after wait_for_begin'

        # stop=raw_input('cont?')
Exemplo n.º 4
0
            page.switch_do(driver, process)
            MixFlag = False


if __name__ == '__main__':
    try:
        platfm.init()
        proc.forks()
        print 'after forks'

        driver = webdriver.Chrome()
        driver.set_window_position(0, 0)
        driver.set_window_size(ScreenW, ScreenH1)

        # platfm.first_timeout(driver)
        page.call_ignore(driver.get, HomeUrl)
        print 'after get the homepage'

        if TestMode:
            # 如果不执行wait_for_begin,就必须刷新一次,否则选地址的div挡着没法点击链接
            print 'TestMode'
            xpath = "//div[@class='area_choose']/dl[3]/dd/a[7]"
            ele = WebDriverWait(driver, 30).until(
                EC.element_to_be_clickable((By.XPATH, xpath)))
            print 'before click'
            ele.click()  # 选择地区
        else:
            print 'Non-TestMode'
            page.wait_for_begin(driver)
            print 'after wait_for_begin'