Esempio n. 1
0
 def see_images(self):
     try:
         imgs_xp = '//div[@id="altImages"]/ul/li[contains(@class, "item")]'
         elems = self.d.is_elements_exist(imgs_xp)
         if elems:
             for i in elems:
                 self.d.jump_to_hold(i)
                 rand_stay()
     except Exception, e:
         print '<see images>: 失败-->', e
Esempio n. 2
0
 def search(self):
     review_xp = '//h2[@id="dp-customer-review-header"]'
     self.d.move_to_node(review_xp)
     print '等待qa加载出来。。。'
     util.rand_stay(1, 2)
     qa_id = self._search_all_qa()
     if qa_id:
         Rdb.insert_log(self.conf.task_guid, self.conf.user, 'QA问答',
                        '找到提问(id:%s)' % self.conf.question_id)
         return qa_id
     else:
         Log.info('未找到提问:%s' % self.conf.question_id)
         Rdb.insert_log(self.conf.task_guid, self.conf.user, 'QA问答',
                        '未找到提问(id:%s)' % self.conf.question_id)
Esempio n. 3
0
 def answer_yes_no(self, qa_id):
     try:
         question_xp = '//div[@id="question-{0}"]/div/div[2]/a'.format(
             qa_id)
         self.d.move_to_click(question_xp)
         answer_id = self.conf.answerer_id
         chose = self.conf.answer_help
         next_xp = '//div[@id="askPaginationBar"]//li[last() and @class="a-last"]'
         end_xp = '//div[@id="askPaginationBar"]//li[last() and @class="a-disabled a-last"]'
         yes_xp = '//form[@id="askVoteHelpfulForm-{0}"]'.format(answer_id)
         no_xp = '//form[@id="askVoteUnHelpfulForm-{0}"]'.format(answer_id)
         map_ = {1: yes_xp, 2: no_xp}
         xp = map_[chose]
         while 1:
             selector = etree.HTML(self.d.page_source)
             util.rand_stay(2, 3)
             if len(selector.xpath(end_xp)):
                 if len(selector.xpath(xp)):
                     self.d.move_to_click(xp)
                     Rdb.insert_log(self.conf.task_guid, self.conf.user,
                                    'QA问答', '问答点赞成功')
                     return True
                 else:
                     Rdb.insert_log(self.conf.task_guid, self.conf.user,
                                    'QA问答',
                                    '未找到回答(id:%s' % self.conf.answerer_id)
                     return False
             elif len(selector.xpath(next_xp)):
                 if len(selector.xpath(xp)):
                     self.d.move_to_click(xp)
                     Rdb.insert_log(self.conf.task_guid, self.conf.user,
                                    'QA问答', '问答点赞成功')
                     return True
                 else:
                     self.d.click_opt(next_xp)
             else:
                 if len(selector.xpath(xp)):
                     self.d.move_to_click(xp)
                     Rdb.insert_log(self.conf.task_guid, self.conf.user,
                                    'QA问答', '问答点赞成功')
                     return True
                 else:
                     Rdb.insert_log(self.conf.task_guid, self.conf.user,
                                    'QA问答',
                                    '未找到回答(id:%s' % self.conf.answerer_id)
                     return False
     except:
         Rdb.insert_log(self.conf.task_guid, self.conf.user, 'QA问答',
                        '问答点赞失败')
         return False
Esempio n. 4
0
 def search_page(self):
     next_xp = '//div[@id="cm_cr-pagination_bar"]//li[last()]'
     end_xp = '//div[@id="cm_cr-pagination_bar"]//li[@class="a-disabled a-last"]'
     while 1:
         selector = etree.HTML(self.d.page_source)
         util.rand_stay(2, 3)
         node = self.match_review(selector)
         if len(selector.xpath(next_xp)):
             if node is not None:
                 return node
             else:
                 self.d.move_to_click(next_xp)
                 # print '查找下一页'
         elif len(selector.xpath(end_xp)):
             return node
         else:
             return node
Esempio n. 5
0
 def vote(self, qa_id):
     try:
         vote_xp = '//div[./div[2]/div[@id="question-{0}"]]/div[1]'.format(
             qa_id)
         vote_up = vote_xp + '/ul/li[1]/form/input[last()]'
         vote_down = vote_xp + '/ul/li[last()]/form/input[last()]'
         map_ = {1: vote_up, 0: vote_down}
         xp = map_[self.conf.vote]
         self.d.move_to_node(vote_xp)
         util.rand_stay(2, 4)
         self.d.click_opt(xp)
         Rdb.insert_log(self.conf.task_guid, self.conf.user, 'QA问答',
                        'vote投票成功')
         return True
     except:
         Rdb.insert_log(self.conf.task_guid, self.conf.user, 'QA问答',
                        'vote投票失败')
         return False
Esempio n. 6
0
 def search_by_cata(self, ):
     try:
         if len(self.conf.option_value):
             select_cata = '//select[@id="searchDropdownBox"]'
             if self.d.is_element_exist(select_cata):
                 value = self.conf.option_value
                 rand_stay(2, 3)
                 self.d.select(select_cata, value)
                 return True
             else:
                 Log.error('<search_by_cata>: 父类目节点未找到,页面未加载出来')
                 return False
         else:
             Log.info('<search by cata>: 未收到父类目设置参数,父类目将不做设置')
             return True
     except:
         Log.error('<search_by_cata>: 未找到父类目节点')
         return False
Esempio n. 7
0
 def _checkout(self):
     """结算点击完判断一次,如果失败再点击结算"""
     try:
         ct_xp = '//div[@id="huc-v2-order-row-container"]//a[@id="hlb-ptc-btn-native"]'
         ct_xp2 = '//input[@name="proceedToCheckout"]'
         ct_xp3 = '//*[@id="hlb-ptc-btn-bottom"]//a[@id="hlb-ptc-btn-native-bottom"]'
         if self.d.is_element_exist(ct_xp):
             self.d.click_opt(ct_xp)
             L.info('<checkout>: 开始结算')
             if self.d.is_element_exist(ct_xp):
                 rand_stay()
                 self.d.click_opt(ct_xp)
             return True
         elif self.d.is_element_exist(ct_xp2):
             self.d.click_opt(ct_xp2)
             L.info('<checkout>: 开始结算')
             if self.d.is_element_exist(ct_xp2):
                 rand_stay()
                 self.d.click_opt(ct_xp2)
             return True
         elif self.d.is_element_exist(ct_xp3):
             self.d.move_to_click(ct_xp3)
             L.info('<checkout>: 开始结算')
             if self.d.is_element_exist(ct_xp3):
                 rand_stay()
                 self.d.move_to_click(ct_xp3)
             return True
         else:
             L.info('<checkout>: 结算失败')
             return False
     except:
         return False
Esempio n. 8
0
    def _search_from_deep_pages(self):
        next_xp = '//div[@id="askPaginationBar"]//li[last()]'
        end_xp = '//div[@id="askPaginationBar"]//li[@class="a-disabled a-last"]'
        while 1:
            selector = etree.HTML(self.d.page_source)
            util.rand_stay(2, 3)
            qa_id = self._match_question(selector)

            if len(selector.xpath(end_xp)):
                if not qa_id:
                    print 'Failed to match question'
                    break
                else:
                    return qa_id
            elif len(selector.xpath(next_xp)):
                if not qa_id:
                    self.d.move_to_click(next_xp)
                else:
                    print 'matched question'
                    return qa_id
            else:
                print 'cant find next or end xpath'
                return qa_id
Esempio n. 9
0
def add_address(driver, conf):
    try:
        account_xp = '//a[@id="nav-link-accountList"]'
        addr_xp = '//a[div[@data-card-identifier="Addresses"]]'
        add_addr_xp = '//div[@id="ya-myab-plus-address-icon"]'
        country_xp = '//span[@id="address-ui-widgets-countryCode"]'
        fullname_xp = '//input[@id="address-ui-widgets-enterAddressFullName"]'
        addr_line1 = '//input[@id="address-ui-widgets-enterAddressLine1"]'
        addr_line2 = '//input[@id="address-ui-widgets-enterAddressLine2"]'
        city_xp = '//input[@id="address-ui-widgets-enterAddressCity"]'
        state_xp = '//input[@id="address-ui-widgets-enterAddressStateOrRegion"]'
        zip_code_xp = '//input[@id="address-ui-widgets-enterAddressPostalCode"]'
        phoneNo_xp = '//input[@id="address-ui-widgets-enterAddressPhoneNumber"]'
        add_btn = '//input[@class="a-button-input" and @type="submit"]'
        save_btn = '//input[@name="address-ui-widgets-saveOriginalOrSuggestedAddress"]'
        driver.click_opt(account_xp)
        driver.wait_clickable(addr_xp)
        driver.click_opt(addr_xp)
        driver.wait_clickable(add_addr_xp)
        driver.click_opt(add_addr_xp)
        driver.wait_clickable(country_xp)
        driver.wait(fullname_xp)
        driver.wait(addr_line1)
        driver.wait(addr_line2)
        driver.wait(city_xp)
        driver.wait(state_xp)
        driver.wait(zip_code_xp)
        driver.wait(phoneNo_xp)
        driver.click_opt(country_xp)
        c_us = '//div[@aria-hidden="false" and @data-action="a-popover-a11y"]//li/a[text()="United States"]'
        c_uk = '//div[@aria-hidden="false" and @data-action="a-popover-a11y"]//li/a[text()="United Kingdom"]'
        c_ca = '//div[@aria-hidden="false" and @data-action="a-popover-a11y"]//li/a[text()="Canada"]'
        c_jp = '//div[@aria-hidden="false" and @data-action="a-popover-a11y"]//li/a[text()="Japan"]'
        c_de = '//div[@aria-hidden="false" and @data-action="a-popover-a11y"]//li/a[text()="Germany"]'
        c_fr = '//div[@aria-hidden="false" and @data-action="a-popover-a11y"]//li/a[text()="France"]'
        c_es = '//div[@aria-hidden="false" and @data-action="a-popover-a11y"]//li/a[text()="Spain"]'
        c_it = '//div[@aria-hidden="false" and @data-action="a-popover-a11y"]//li/a[text()="Italy"]'
        c_au = '//div[@aria-hidden="false" and @data-action="a-popover-a11y"]//li/a[text()="Australia"]'
        map_ = {
            1: c_us,
            2: c_uk,
            3: c_ca,
            4: c_jp,
            5: c_de,
            6: c_fr,
            7: c_es,
            8: c_it,
            9: c_au
        }
        for i in xrange(20):
            util.rand_stay(0.5, 1)
            driver.press_key(country_xp)
            if driver.is_element_exist(map_[conf.addr_cty]):
                driver.click_opt(map_[conf.addr_cty])
                break
        driver.click_opt(fullname_xp)
        util.rand_stay(2, 3)
        driver.send_key(fullname_xp, conf.fullname)
        driver.send_key(addr_line1, conf.streetaddr)
        driver.send_key(city_xp, conf.city)
        driver.send_key(state_xp, conf.state)
        driver.send_key(zip_code_xp, conf.zip_code)
        driver.send_key(phoneNo_xp, conf.phoneNo)
        driver.click_opt(add_btn)
        util.rand_stay()
        if driver.is_element_exist(add_btn):
            driver.move_to_click(add_btn)
            if driver.is_element_exist(add_btn):
                # bo.update_cookie_to_db(driver, conf.guid, conf.user, '邮箱注册', '地址初始化')
                Log.error('地址信息未被Amazon识别,保存失败')
                Rdb.insert_log(conf.guid, conf.user, '邮箱注册',
                               '添加地址,: 地址信息未被Amazon识别,保存失败')
                Rdb.callProc("exec sys_InsertAccount '%s',2,'注册成功,地址信息填写有误'" %
                             conf.guid)
            else:
                Log.error('地址信息未被Amazon识别,但仍保存成功')
                Rdb.insert_log(conf.guid, conf.user, '邮箱注册',
                               '添加地址: 地址信息未被Amazon识别,强制保存成功')
                Rdb.callProc("exec sys_InsertAccount '%s',2,'注册成功,地址设置成功'" %
                             conf.guid)
        else:
            if driver.is_element_exist(save_btn):
                driver.click_opt(save_btn)
            Log.info('Succeed to save addr.')
            Rdb.insert_log(conf.guid, conf.user, '邮箱注册', '添加地址: 地址设置成功')
            Rdb.callProc("exec sys_InsertAccount '%s',2,'注册成功,地址设置成功'" %
                         conf.guid)
    except Exception, e:
        # bo.update_cookie_to_db(driver, conf.guid, conf.user, '邮箱注册', '地址初始化')
        Log.exc("<add addr> 地址设置失败。(%s)" % e)
        Rdb.insert_log(conf.guid, conf.user, '邮箱注册', '添加地址: 地址设置失败(请检查操作节点)')
        Rdb.callProc("exec sys_InsertAccount '%s',2,'注册成功,地址设置失败'" % conf.guid)
Esempio n. 10
0
 def start(self):
     try:
         login_xp = str()
         if self.conf.cid in (2, 5):
             login_xp = '//a[@id="nav-link-yourAccount"]'
         elif self.conf.cid in (1, 3, 4, 6, 7, 8):
             login_xp = '//a[@id="nav-link-accountList"]'
         create_xp = '//a[@id="createAccountSubmit"]'
         yourname = '//input[@id="ap_customer_name"]'
         email_xp = '//input[@id="ap_email"]'
         pw_xp = '//input[@id="ap_password"]'
         recheck_xp = '//input[@id="ap_password_check"]'
         alert = r".*Email address already in use.*"
         ctn_xp = '//input[@id="continue"]'
         url = 'https://' + util.CidTransfer(self.conf.cid).value
         if self.d.request(url):
             if self.d.wait_clickable(login_xp):
                 # self.d.rand_move()
                 self.d.click_opt(login_xp)
                 self.d.wait_clickable(create_xp)
                 self.d.click_opt(create_xp)
                 self.d.wait(yourname)
                 self.d.wait(email_xp)
                 self.d.wait(pw_xp)
                 self.d.wait(recheck_xp)
                 self.d.wait_clickable(ctn_xp)
                 self.d.send_key(yourname, self.conf.yourname)
                 self.d.send_key(email_xp, self.conf.user)
                 self.d.send_key(pw_xp, self.conf.pw)
                 self.d.send_key(recheck_xp, self.conf.pw)
                 self.d.click_opt(ctn_xp)
                 util.rand_stay(5, 8)
                 if re.match(alert, str(self.d.page_source), re.S):
                     L.error('The email has been registed!')
                     Rdb.insert_log(self.conf.guid, self.conf.user, '邮箱注册',
                                    '注册失败, 邮箱被注册过')
                     Rdb.callProc("exec sys_InsertAccount '%s',3,'邮箱已注册'" %
                                  self.conf.guid)
                     util.rand_stay(5, 6)
                     self.d.quit_opt()
                     return False
                 else:
                     # if self.d.flag:
                     bo.insert_cookie_to_db(self.d, self.conf.guid,
                                            self.conf.user)
                     L.info('%s 注册成功' % self.conf.user)
                     Rdb.insert_log(self.conf.guid, self.conf.user, '邮箱注册',
                                    '注册成功(个人资料未初始化)')
                     Rdb.callProc("exec sys_InsertAccount '%s',2,'注册成功'" %
                                  self.conf.guid)
                     return True
                     # else:
                     #     L.info('%s 注册失败' % self.conf.user)
                     #     Rdb.insert_log(self.conf.guid, self.conf.user, '邮箱注册', '注册失败(请检查操作节点)')
                     #     Rdb.callProc("exec sys_InsertAccount '%s',3,'注册失败'" % self.conf.guid)
                     #     self.d.quit_opt()
                     #     return False
             else:
                 L.info('%s 注册失败' % self.conf.user)
                 Rdb.insert_log(self.conf.guid, self.conf.user, '邮箱注册',
                                '注册失败(当前user-agent请求的页面未找到登录节点)')
                 Rdb.callProc("exec sys_InsertAccount '%s',3,'注册失败'" %
                              self.conf.guid)
                 return False
         else:
             L.info('%s 注册失败' % self.conf.user)
             Rdb.insert_log(self.conf.guid, self.conf.user, '邮箱注册',
                            '注册失败(代理网速过慢,请求失败)')
             Rdb.callProc("exec sys_InsertAccount '%s',3,'注册失败'" %
                          self.conf.guid)
             return False
     except Exception, e:
         L.exc('<regist>: 注册失败。(%s)' % e)
         Rdb.insert_log(self.conf.guid, self.conf.user, '邮箱注册',
                        '注册失败(请检查操作节点)')
         Rdb.callProc("exec sys_InsertAccount '%s',3,'注册失败'" %
                      self.conf.guid)
         return False
Esempio n. 11
0
def add_profile(driver, conf):
    try:
        account = '//a[@id="nav-link-accountList"]'
        profile_xp = '//div[@data-card-identifier="OrderingAndShoppingPreferences"]//a[contains(@href, "profile")]'
        add_btn_xp = '//div[@id="pr-upload-button"]/div[2]//img'
        notnow_xp = '//span[./span[@id="a-autoid-0-announce"]]'
        sub_xp = '//span[./span[@id="a-autoid-3-announce"]]'
        edit_xp = '//a[contains(@href, "edit_activity_settings")]'
        add_btn2 = '//div[contains(@class, "image-edit-popover-trigger-holder")]'
        upload_xp = '//label[@class="imageUploadLabel"]'
        close_xp = '//button[@data-action="a-popover-close"]'
        bio_xp = '//textarea[@id="profile_personal_description"]'
        fb_xp = '//input[@id="profile_social_facebook"]'
        twitter_xp = '//input[@id="profile_social_twitter"]'
        youtube_xp = '//input[@id="profile_social_youtube"]'
        pint_xp = '//input[@id="profile_social_pinterest"]'
        instagram_xp = '//input[@id="profile_social_instagram"]'
        save_xp = '//span[@data-pr-edit]/span[@id="save-public-activity"]'
        driver.click_opt(account)
        driver.move_to_node(profile_xp)
        driver.click_opt(profile_xp)
        if os.path.exists(conf.imgPath):
            if driver.is_element_exist(notnow_xp):  # 第一种情况,从没上传过头像的页面
                driver.click_opt(add_btn_xp)
                SendKeys.SendKeys(r'' + conf.imgPath)
                util.rand_stay(2, 3)
                SendKeys.SendKeys("{ENTER}")
                util.rand_stay(2, 3)
                driver.click_opt(sub_xp)  #?AMZ 有问题, 提交不了的话点notNow
            else:  # 曾经上传过头像的页面
                driver.click_opt(add_btn2)
                driver.click_opt(upload_xp)
                SendKeys.SendKeys(r'' + conf.imgPath)
                SendKeys.SendKeys("{ENTER}")
            Rdb.insert_log(conf.guid, conf.user, '邮箱注册', '添加画像: 头像图片添加成功')
        else:
            Log.error('<add profile>: Wrong image path, it does not exist.')
            Rdb.insert_log(conf.guid, conf.user, '邮箱注册',
                           '添加画像: 头像图片添加失败,请检查路径')
        util.rand_stay(5, 6)
        #
        if driver.is_element_exist(close_xp):
            driver.click_opt(close_xp)
        driver.click_opt(edit_xp)
        driver.send_key(bio_xp, conf.bio)
        driver.send_key(fb_xp, conf.fb)
        driver.send_key(twitter_xp, conf.twitter)
        driver.send_key(youtube_xp, conf.youtube)
        driver.send_key(pint_xp, conf.pint)
        driver.send_key(instagram_xp, conf.instagram)
        driver.click_opt(save_xp)
        if driver.flag:
            Log.info("Profile modification finished")
            # bo.update_cookie_to_db(driver, conf.guid, conf.user, '邮箱注册', '画像初始化')
            Rdb.insert_log(conf.guid, conf.user, '邮箱注册',
                           '添加画像: 画像修改成功, 资料已初始化')
            Rdb.callProc("exec sys_InsertAccount '%s',2,'注册成功,资料已初始化'" %
                         conf.guid)
        else:
            # bo.update_cookie_to_db(driver, conf.guid, conf.user, '邮箱注册', '画像初始化')
            Rdb.insert_log(conf.guid, conf.user, '邮箱注册', '添加画像: 画像修改失败')
            Rdb.callProc("exec sys_InsertAccount '%s',2,'注册成功,添加画像失败'" %
                         conf.guid)
    except Exception, e:
        # bo.update_cookie_to_db(driver, conf.guid, conf.user, '邮箱注册', '画像初始化')
        Log.exc("<add profile>: 画像添加失败。(%s)" % e)
        Rdb.insert_log(conf.guid, conf.user, '邮箱注册', '添加画像: 画像修改失败')
        Rdb.callProc("exec sys_InsertAccount '%s',2,'注册成功,添加画像失败'" % conf.guid)