美文网首页
python selenium 自动上传有赞单号

python selenium 自动上传有赞单号

作者: 云胡同学 | 来源:发表于2018-07-03 21:12 被阅读0次
    思路
    1. 将姓名和单号填入 excel 表格里面


    2. 读取 excel 表格,将所有姓名存到 ExeclName 这个 list 中,单号存到 ExeclId

    3. selenium 自动根据姓名搜索,点击发货

    代码
    # -- coding: utf-8 --
    from selenium import webdriver
    import time
    import 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 自动上传有赞单号

          本文链接:https://www.haomeiwen.com/subject/ecajuftx.html