爬行网页,形成动作,然后使用硒遍历下一页

时间:2019-01-23 02:31:53

标签: python-3.x selenium selenium-webdriver

driver.get('url')


#login 
driver.find_element_by_xpath('//*[@id="input-username"]').send_keys('username')
driver.find_element_by_xpath('//*[@id="input-password"]').send_keys('password')
driver.find_element_by_xpath('//*[@id="content"]/div/div/div/div/div[2]/form/div[3]/button').click()


'''selecting supplier and modifying the content from drop down list'''


def select_supplier():
    driver.find_element_by_xpath('//*[@id="seller_id"]').click()
    driver.find_element_by_xpath('//*[@id="seller_id"]/option[2]').click()
    time.sleep(1.0)
    #select supplier from the drop down list (The tick)
    driver.find_element_by_xpath('//*[@id="ms-bulk-sel-apply"]').click()
    #Select all products
    driver.find_element_by_class_name('sorting_disabled').click()
    driver.find_element_by_xpath('//*[@id="ms-bulk-sel-apply"]').click()
    time.sleep(2.0)

# def select_all_products():
#     driver.find_element_by_xpath('//*[@id="list-products"]/thead/tr[1]/td[1]/input').click()
#clicking next

def click_next():
    driver.find_element_by_xpath('//*[@id="list-products_next"]').click()

def number_clicks(times, select_supplier, click_next):
    for i in range(times):
        select_supplier()
        click_next()


number_clicks(53, select_supplier, click_next)

我正在网站上自动执行一项操作,从中选择产品列表并将其归因于特定的供应商。 我能够登录并执行逻辑,但是它只执行前2页,然后返回到第一页并再次执行相同的功能。

0 个答案:

没有答案