python selenium自动上传有赞单号的操作方法
程序员文章站
2022-06-14 17:13:31
思路
1.将姓名和单号填入excel表格里面
2.读取excel表格,将所有姓名存到execlname这个list中,单号存到execlid
3.selenium...
思路
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 Django做网页
下一篇: 黑豆可以打豆浆吗,还有什么营养呢