(page)
抓取索引页
    :param page: 页码
抓取索引页
    :param page: 页码
抓取索引页 : param page : 页码
def index_page(page):
    """
    抓取索引页
    :param page: 页码
    """
    print('正在爬取第', page, '页')
    try:
        url = 'https://s.taobao.com/search?q=' + quote(KEYWORD)
        browser.get(url)
        if page > 1:
            input = wait.until(
                EC.presence_of_element_located((By.CSS_SELECTOR, '#mainsrp-pager div.form > input')))
            submit = wait.until(
                EC.element_to_be_clickable((By.CSS_SELECTOR, '#mainsrp-pager div.form > span.btn.J_Submit')))
            input.clear()
            input.send_keys(page)
            submit.click()
        wait.until(
            EC.text_to_be_present_in_element((By.CSS_SELECTOR, '#mainsrp-pager li.item.active > span'), str(page)))
        wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, '.m-itemlist .items .item')))
        get_products()
    except TimeoutException:
        index_page(page)
def index_page ( page ) : print ( '正在爬取第', page, '页 ' try : url = 'https://s.taobao.com/search?q=' + quote ( KEYWORD ) browser . get ( url ) if page > 1 : input = wait . until ( EC . presence_of_element_located ( ( By . CSS_SELECTOR , '#mainsrp-pager div.form > input' ) ) ) submit = wait . until ( EC . element_to_be_clickable ( ( By . CSS_SELECTOR , '#mainsrp-pager div.form > span.btn.J_Submit' ) ) ) input . clear ( ) input . send_keys ( page ) submit . click ( ) wait . until ( EC . text_to_be_present_in_element ( ( By . CSS_SELECTOR , '#mainsrp-pager li.item.active > span' ) , str ( page ) ) ) wait . until ( EC . presence_of_element_located ( ( By . CSS_SELECTOR , '.m-itemlist .items .item' ) ) ) get_products ( ) except TimeoutException : index_page ( page )