def qq_auth_login(self):
        # QQ授权登录
        try:
            qq_login = findElement(self.driver, (
                By.CSS_SELECTOR,
                'body > section > div.wrap.loginPage > div.login-type > div.quick-login > a.J_ping.quick-qq'
            ))
            if qq_login is None:
                self.logger.info("QQ授权登录 未找到")
                return False

            qq_login.click()
            sleep(2)

            # 切换到最新打开的窗口
            window_handles = self.driver.window_handles
            self.driver.switch_to.window(window_handles[-1])

            self.logger.info(self.driver.title)

            # 切换iframe
            i_frame = WebDriverWait(
                self.driver,
                5).until(lambda d: d.find_element_by_id('ptlogin_iframe'))
            self.driver.switch_to.frame(i_frame)

            # 点击头像进行授权登录
            qq_face = findElement(self.driver,
                                  (By.XPATH, '//*[@id="qlogin_list"]/a[1]'))
            if qq_face and qq_face.is_displayed:
                qq_face.click()
            # else:
            #     self.logger.warning("QQ未登录,只能扫描登录")
            #     # qr_area = WebDriverWait(self.driver, 5).until(lambda d: d.find_element_by_id('qr_area'))
            #     # print()

            # 循环检测是否登陆
            while True:
                try:
                    WebDriverWait(self.driver, 10).until(
                        EC.url_contains(self.home_page[-13:]))
                    break
                except TimeoutException:
                    self.logger.warning(
                        "JD m-mall logging, please scan the QR code with QQ..."
                    )
                    continue
            self.logger.info('JD m-mall login success!')
            return True
        except Exception:
            self.logger.exception(sys.exc_info())
            return False
    def batch_unfollow_fav(self):
        self.driver.get("https://wqs.jd.com/my/fav/shop_fav.shtml")

        i = 1
        while True:
            try:
                subscribe_nothing = WebDriverWait(self.driver, 3, 0.5).until(
                    EC.visibility_of_element_located(
                        (By.ID, "shoplist_nothing")))
                if subscribe_nothing and subscribe_nothing.is_displayed():
                    self.logger.info("已无收藏的店铺")
                    break

                if EC.visibility_of_element_located((By.ID, "shoplist_edit")):
                    findElement(self.driver, (By.ID, "shoplist_edit")).click()

                if EC.visibility_of_element_located((By.ID, "selectAllBtn")):
                    findElement(self.driver, (By.ID, "selectAllBtn")).click()

                if EC.visibility_of_element_located((By.ID, "multiCancle")):
                    findElement(self.driver, (By.ID, "multiCancle")).click()

                if EC.visibility_of_element_located((By.ID, "ui_btn_confirm")):
                    findElement(self.driver, (By.ID, "ui_btn_confirm")).click()

                self.logger.info("取消第{}批收藏的店铺".format(str(i)))
                i = i + 1

                sleep(2)
            except Exception as e:
                self.logger.error("批量取消收藏店铺异常...")
                break
Exemple #3
0
    def qq_auth_login(self):
        try:
            # QQ授权登录
            qq_login = findElement(
                self.driver,
                (By.CSS_SELECTOR, '#kbCoagent > ul > li:nth-child(1)'))
            if qq_login is None:
                self.logger.info("QQ授权登录 未找到")
                return False

            qq_login.click()
            sleep(2)

            # 切换到最新打开的窗口
            window_handles = self.driver.window_handles
            self.driver.switch_to.window(window_handles[-1])
            self.logger.info(self.driver.title)

            # 切换iframe
            i_frame = WebDriverWait(
                self.driver,
                5).until(lambda d: d.find_element_by_id('ptlogin_iframe'))
            self.driver.switch_to.frame(i_frame)

            # 点击头像进行授权登录
            qq_face = findElement(self.driver,
                                  (By.XPATH, '//*[@id="qlogin_list"]/a[1]'))
            if qq_face and qq_face.is_displayed:
                qq_face.click()
            # else:
            #     self.logger.warning("QQ未登录,只能扫描登录")
            #     # qr_area = WebDriverWait(self.driver, 5).until(lambda d: d.find_element_by_id('qr_area'))
            #     # print()

            # 循环检测是否登陆
            while True:
                try:
                    WebDriverWait(self.driver, 10).until(
                        EC.url_contains(self.home_page[-12:]))
                    break
                except TimeoutException as e:
                    self.logger.warning("Please scan the QR code with QQ " +
                                        str(e.msg))
                    continue

            self.logger.info('JD PC login success with QQ auth!')
            return True
        except Exception:
            self.logger.exception(sys.exc_info())
            return False
Exemple #4
0
    def account_login(self):
        try:
            # 账户登陆
            findElement(self.driver, (
                By.CSS_SELECTOR,
                '#content > div.login-wrap > div.w > div > div.login-tab.login-tab-r'
            )).click()
            findElement(self.driver,
                        (By.ID, "loginname")).send_keys(config.jd["username"])
            findElement(self.driver,
                        (By.ID, "nloginpwd")).send_keys(config.jd["password"])
            findElement(self.driver, (By.ID, "loginsubmit")).click()

            # 循环检测是否登陆
            while True:
                try:
                    WebDriverWait(self.driver, 10).until(
                        EC.url_contains(self.home_page[-12:]))
                    break
                except TimeoutException:
                    if EC.visibility_of_element_located(
                        (By.CSS_SELECTOR,
                         "# JDJRV-wrap-loginsubmit > div > div > div")):
                        self.logger.info("JD PC logging,please pic auth...")
                    continue

            self.logger.info('JD PC login success!')
            return True
        except Exception:
            self.logger.exception(sys.exc_info())
            return False
    def account_login(self):
        try:
            findElement(self.driver,
                        (By.ID, "username")).send_keys(config.jd["username"])
            findElement(self.driver,
                        (By.ID, "password")).send_keys(config.jd["password"])
            findElement(self.driver, (By.ID, "loginBtn")).click()

            # 循环检测是否登陆
            while True:
                try:
                    WebDriverWait(self.driver, 10).until(
                        EC.url_contains(self.home_page[-13:]))
                    break
                except TimeoutException:
                    if EC.visibility_of_element_located(
                        (By.XPATH, "//*[@id=\"captcha\"]")):
                        self.logger.warning(
                            "JD m-mall logging, please pic auth...")
                    continue

            self.logger.info('JD m-mall login success!')
            return True
        except Exception:
            self.logger.exception(sys.exc_info())
            return False
    def collect_shop_info(self, short_link):
        try:
            self.browser.get(short_link)

            title = self.browser.title.title()
            long_link = self.browser.current_url

            self.logger.info(title + " : " + long_link)

            if long_link is None or len(long_link) <= 0:
                return None

            path_part, param_part = splitquery(long_link)
            params = parse_qs(param_part) if param_part else None
            if re.match(re_jd_login_url, path_part):
                self.logger.error("please login first...")
                # JD_Auto_Login().auto_login()
                # time.sleep(1)
                #
                # update_chrome_cookies(worker_browser)
                # time.sleep(3)
            if re.match(re_shop_url, path_part):
                shop_name = self.browser.title.title()

                shop_id_element = findElement(
                    self.browser,
                    (By.XPATH, "//*[@id=\"searchform\"]/input[2]"))
                shop_id = shop_id_element.get_attribute(
                    "value") if shop_id_element else ""

                vender_id_element = findElement(
                    self.browser,
                    (By.XPATH, "//*[@id=\"searchform\"]/input[3]"))
                vender_id = vender_id_element.get_attribute(
                    "value") if vender_id_element else ""

                shop_url = "https://wqshop.jd.com/mshop/gethomepage?venderid=" + vender_id
                shop_info = {
                    'shopName': shop_name,
                    'venderId': vender_id,
                    'shopId': shop_id,
                    'shopUrl': shop_url
                }

                # Shop(vender_id, shop_id, shop_name).run()

                if self.shop_total.get(vender_id, None) is None:
                    self.logger.info("new shop: {}".format(str(shop_info)))
                    self.shop_total[vender_id] = shop_info
                    self.shop_new[vender_id] = shop_info

                insert_sql = "insert or replace into {}(shopName,venderId,shopId,shopUrl) values('{}','{}','{}','{}')".format(
                    table_name, shop_name, vender_id, shop_id, shop_url)
                self.cur.execute(insert_sql)
                self.conn.commit()

            elif re.match(re_shop_draw_url, path_part) and params:
                vender_id = params.get('venderid') or params.get('venderId')
                if vender_id:
                    url = "https://wqshop.jd.com/mshop/gethomepage?venderid=" + vender_id[
                        0]
                    self.collect_shop_info(url)

        except Exception:
            self.logger.exception(sys.exc_info())