Posted in Python onJuly 05, 2018
思路
1.将姓名和单号填入excel表格里面
2.读取excel表格,将所有姓名存到ExeclName这个list中,单号存到ExeclId
3.selenium自动根据姓名搜索,点击发货
代码
# -- coding: utf-8 -- from selenium import webdriver import timeimport xlwings as xw from selenium.common.exceptions import NoSuchElementException browser = webdriver.Chrome() #输入有赞账号密码 def loginYouzan(): browser.get('https://www.youzan.com/v2/trade/order#list&p=1&goods_title=&type=all&state=tosend&orderby=book_time&order_es_tag=&tuanId=&showBanner=false&ext_type=&order=desc&page_size=20&disable_express_type=') time.sleep(1) browser.find_element_by_name('mobile').send_keys("username") time.sleep(0.5) browser.find_element_by_name('password').send_keys("password") #自动上传单号 def autoUploadId(): wb = xw.Book('upload.xlsx') sht = xw.books['upload.xlsx'].sheets['Sheet1'] ExeclId = sht.range('C2').expand('down') # 从excel获取id #从c2开始的底下所有列的值存到list rng1中 ExeclName = sht.range('B2').expand('down') # 从excel中获取名字 print(ExeclId.value) print(ExeclName.value) time.sleep(5) loginYouzan() time.sleep(5) redBg = browser.find_elements_by_class_name('dp-text') time.sleep(1) #redBg[1].click() redBg[0].click() time.sleep(1) #browser.find_element_by_name("order_label").find_elements_by_tag_name("option")[2].click() browser.find_element_by_name("order_label").find_elements_by_tag_name("option")[2].click() i = 0 while i < len(ExeclName): time.sleep(2) browser.find_element_by_name('user_name').click() browser.find_element_by_name('user_name').clear() browser.find_element_by_name('user_name').send_keys(ExeclName[i].value) # 填入获取到的名字 time.sleep(1) browser.find_element_by_link_text('筛选').click() # 点击筛选 time.sleep(2) try: submit = browser.find_element_by_link_text('发 货') if submit.is_displayed(): if submit.is_enabled(): submit.click() # 点击发货 time.sleep(3) browser.find_element_by_class_name('js-check-all').click() time.sleep(2) browser.find_element_by_name("express_id").find_elements_by_tag_name("option")[5].click() browser.find_element_by_name('express_no').send_keys(ExeclId[i].value) # 填入单号 print("第" + str(i) + "个客户成功") print('姓名: ' + ExeclName[i].value + "单号: " + ExeclId[i].value) time.sleep(4) # browser.find_element_by_link_text('保存').click() #点击保存 browser.find_element_by_link_text('×').click() #i = i + 1 browser.find_element_by_name('user_name').clear() else: continue except NoSuchElementException as msg: print(msg) print("第" + str(i) + "个客户失败") i = i + 1 print('姓名: ' + ExeclName[i].value + "单号: " + ExeclId[i].value) time.sleep(0.5) def main(): #writeDataToExcel() autoUploadId() if __name__ == '__main__': main()
总结
以上所述是小编给大家介绍的python selenium自动上传有赞单号的操作方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对三水点靠木网站的支持!
python selenium自动上传有赞单号的操作方法
- Author -
云胡123声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@