コード例 #1
0
    def start(self):
        try:
            # if self.connect(site_url=self.UNFOLLOW_URL, is_proxy=False, default_driver='selenium', is_chrome=True) is False:
            #     raise Exception('site connect fail')
            #
            # self.following()
            # exit()

            # 보안 블럭 관련 데이터 가져오기
            self.security_code = filewriter.get_log_file('instagram_security_code')

            # 블럭 상태라면 security_code가 입력될 때 까지는 종료
            if self.security_code[0] == 'blocked':
                log.logger.info('Instagram is blocked.')
                self.destroy()
                exit()

            # 복사된 태그 가져오기
            self.tag = filewriter.get_log_file('instagramcollecttag_copied')

            # 파일이 없다면 태그파일 복사본을 생성
            if self.tag is None or len(self.tag) == 0:
                self.tag = filewriter.get_log_file('instagramcollecttag')
                filewriter.save_log_file('instagramcollecttag_copied', self.tag)

            # 태그를 생성할 수 없다면 종료
            if self.tag is None:
                self.destroy()
                exit()

            # 태그 랜덤으로 섞기
            random.shuffle(self.tag)

            self.login()

            # self.driver.save_screenshot('instagram_screenshot.png')
            # self.destroy()
            # exit()

            # 작업 시작

            # 팔로워 정리
            if self.follower() is True:
                # 팔로윙 정리
                self.following()

            # 작업 시작
            self.scan_page()

            self.end_report()

        except Exception as e:
            log.logger.error(e, exc_info=True)
            self.end_report()
コード例 #2
0
    def record_success_log(self):

        try:
            if self.is_record_call is True:
                return False
        except:
            self.is_record_call = True

        # print('called')

        log_success = filewriter.get_log_file('success', is_json=True)
        date = datetime.now().strftime('%Y_%m_%d')
        try:
            if not log_success or not log_success[date]:
                # print('new')
                log_success[date] = {};
        except:
            log_success[date] = {};

        try:
            if log_success[date][self.name]:
                return False
        except:
            log_success[date][self.name] = 1

        log_success[date][self.name] = 1

        # print('recorded')

        filewriter.save_log_file('success', log_success)
コード例 #3
0
ファイル: ppomppu2.py プロジェクト: ko9ma7/crawler-1
    def start(self):
        try:
            self.log = filewriter.get_log_file(self.name)

            if self.connect(
                    site_url=
                    'http://www.ppomppu.co.kr/zboard/zboard.php?id=ppomppu',
                    is_proxy=False,
                    default_driver='selenium',
                    is_chrome=False) is False:
                raise Exception('site connect fail')

            self.scan_page()

            if self.connect(
                    site_url=
                    'http://www.ppomppu.co.kr/zboard/zboard.php?id=ppomppu4',
                    is_proxy=False,
                    default_driver='selenium',
                    is_chrome=False) is False:
                raise Exception('site connect fail')

            self.scan_page()

            self.destroy()

        except Exception as e:
            log.logger.error(e, exc_info=True)
コード例 #4
0
    def login(self):
        try:
            if self.connect(site_url=self.LOGIN_URL,
                            is_proxy=False,
                            default_driver='selenium',
                            is_chrome=True) is False:
                raise Exception('site connect fail')

            # 계정정보 가져오기
            account_data = filewriter.get_log_file('instagram_account')

            if account_data:
                if self.selenium_extract_by_xpath(tag={
                        'tag': 'input',
                        'attr': 'name',
                        'name': 'username'
                }) is False:
                    raise Exception('selenium_extract_by_xpath fail.')

                # 아이디 입력
                if self.selenium_input_text_by_xpath(text=account_data[0],
                                                     tag={
                                                         'tag': 'input',
                                                         'attr': 'name',
                                                         'name': 'username'
                                                     }) is False:
                    raise Exception(
                        'selenium_input_text_by_xpath fail. username')

                # 비번 입력
                if self.selenium_input_text_by_xpath(text=account_data[1],
                                                     tag={
                                                         'tag': 'input',
                                                         'attr': 'name',
                                                         'name': 'password'
                                                     }) is False:
                    raise Exception(
                        'selenium_input_text_by_xpath fail. password')

                # 로그인하기 선택
                if self.selenium_click_by_xpath(tag={
                        'tag': 'button',
                        'attr': 'type',
                        'name': 'submit'
                }) is False:
                    raise Exception('selenium_click_by_xpath fail. submit')

                sleep(3)

                log.logger.info('login success')

                return True
        except Exception as e:
            log.logger.error(e, exc_info=True)
            self.CRITICAL_CNT = self.CRITICAL_CNT + 1
            self.end_report()

        return False
コード例 #5
0
    def remove_proxy_server_ip_list(self):
        proxy_list_from_file = filewriter.get_log_file('proxy')

        if proxy_list_from_file:
            del proxy_list_from_file[0]
            if len(proxy_list_from_file) == 0:
                self.request_proxy_server_ip_list()
            else:
                filewriter.save_log_file('proxy', proxy_list_from_file)
コード例 #6
0
ファイル: crawler.py プロジェクト: ko9ma7/crawler-1
    def get_proxy_server_ip_list(self):
        self.proxy_list_from_file = filewriter.get_log_file('proxy')

        if len(self.proxy_list_from_file) > 0:
            return self.proxy_list_from_file[0]
        else:
            from proxy import Proxy
            proxy = Proxy()
            proxy.start()
            raise Exception('Proxy server ip is not found.')
コード例 #7
0
ファイル: jejuair.py プロジェクト: ko9ma7/crawler-1
    def login(self):
        try:
            if self.is_login:
                return True
        except:
            try:
                self.is_login = True

                # 계정정보 가져오기
                account_data = filewriter.get_log_file(self.name + '_account')
                log.logger.info(account_data)
                if account_data:
                    # 로그인 버튼 선택
                    if self.selenium_click_by_xpath(tag={
                            'tag': 'button',
                            'attr': 'class',
                            'name': 'loginOpen'
                    }) is False:
                        raise Exception(
                            'selenium_click_by_xpath fail. loginOpen')
                    # 아이디 비번 입력
                    if self.selenium_input_text_by_xpath(text=account_data[0],
                                                         tag={
                                                             'tag': 'input',
                                                             'attr': 'name',
                                                             'name':
                                                             'gnb_userid'
                                                         }) is False:
                        raise Exception(
                            'selenium_input_text_by_xpath fail. gnb_userid')
                    if self.selenium_input_text_by_xpath(text=account_data[1],
                                                         tag={
                                                             'tag': 'input',
                                                             'attr': 'name',
                                                             'name': 'gnb_pid'
                                                         }) is False:
                        raise Exception(
                            'selenium_input_text_by_xpath fail. gnb_pid')
                    # 로그인하기 선택
                    if self.selenium_click_by_xpath(tag={
                            'tag': 'div',
                            'attr': 'id',
                            'name': 'gnb_idLogin'
                    }) is False:
                        raise Exception(
                            'selenium_click_by_xpath fail. gnb_idLogin')

                    log.logger.info('login success')
                    time.sleep(5)
                    return True
            except:
                return False
コード例 #8
0
    def start(self):
        try:
            self.log = filewriter.get_log_file(self.name)
            log.logger.info('before tags (%d)' % (len(self.log)))

            if self.connect(site_url=self.DETAIL_URL + self.KEYWORD,
                            is_proxy=False,
                            default_driver='selenium',
                            is_chrome=True) is False:
                raise Exception('site connect fail')

            soup = BeautifulSoup(self.driver.page_source, 'html.parser')
            element = soup.find('table', id="table_result")

            if self.selenium_extract_by_xpath(
                    xpath='//*[@id="table_result"]') is False:
                raise Exception('selenium_extract_by_xpath fail.')

            if element:
                for list in element.find_all('tr'):
                    try:
                        tag = list.find(
                            'td', class_='result_td01').getText().strip()
                        tag = tag.replace("#", "")

                        if tag:
                            if tag not in self.log:
                                log.logger.info(tag)
                                self.log.append(tag)
                                self.ADD_COUNT = self.ADD_COUNT + 1
                    except Exception:
                        continue

            # 제외 단어 정리
            for tag in self.log:
                if any(
                        word in tag for word in
                    ['화장품', '남자', '남성', '피부', '운동화', '태그', '가방', '치마', '스커트']):
                    self.log.remove(tag)
                    self.DEL_COUNT = self.DEL_COUNT + 1

            filewriter.save_log_file(self.name, self.log)
            log.logger.info(
                'add(%d), remove(%d), total(%d) tags has just updated.' %
                (self.ADD_COUNT, self.DEL_COUNT, len(self.log)))

            self.destroy()

        except Exception as e:
            self.destroy()
            log.logger.error(e, exc_info=True)
コード例 #9
0
    def get_proxy_server_ip_list(self):
        try:
            proxy_list_from_file = filewriter.get_log_file('proxy')

            if proxy_list_from_file is None or len(proxy_list_from_file) == 0:
                self.request_proxy_server_ip_list()

            if proxy_list_from_file is None or len(proxy_list_from_file) == 0:
                return False
            else:
                return proxy_list_from_file[0]
        except Exception as e:
            log.logger.error(e, exc_info=True)
            return False
コード例 #10
0
    def start(self):
        try:
            self.log = filewriter.get_log_file(self.name)

            self.login()

            self.scan_page()

            self.destroy()
            exit()

        except Exception as e:
            self.destroy()
            log.logger.error(e, exc_info=True)
コード例 #11
0
    def start(self):
        try:
            self.log = filewriter.get_log_file(self.name)
            self.channels = ['스마트스토어정성한끼', '스마트스토어쿠힛마트']

            self.login()

            self.select_channel()

            self.destroy()
            exit()

        except Exception as e:
            self.destroy()
            log.logger.error(e, exc_info=True)
コード例 #12
0
    def start(self):
        try:
            if self.connect(site_url=self.NAVER_DATALAB_URL,
                            is_proxy=False,
                            default_driver='selenium',
                            is_chrome=True) is False:
                raise Exception('site connect fail')

            self.keywords = filewriter.get_log_file(self.name)

            self.click_next_category()

            self.destroy()

        except Exception as e:
            log.logger.error(e, exc_info=True)
コード例 #13
0
    def start(self):
        try:
            self.log = filewriter.get_log_file(self.name, is_json=True)

            for url in self.DETECT_URLS:
                if self.connect(site_url=url,
                                is_proxy=False,
                                default_driver='selenium',
                                is_chrome=False) is False:
                    raise Exception('site connect fail')

                self.scan_page(url)

            self.destroy()

        except Exception as e:
            log.logger.error(e, exc_info=True)
コード例 #14
0
ファイル: lottecinema2.py プロジェクト: ko9ma7/crawler-1
    def start(self):
        try:
            self.log = filewriter.get_log_file(self.name)

            if self.connect(
                    site_url=
                    'http://event.lottecinema.co.kr/LCHS/Contents/Event/movie-booking-list.aspx',
                    is_proxy=True,
                    default_driver='selenium',
                    is_chrome=False) is False:
                raise Exception('site connect fail')

            self.scan_page()

            self.destroy()

        except Exception as e:
            log.logger.error(e, exc_info=True)
コード例 #15
0
ファイル: jejuair.py プロジェクト: ko9ma7/crawler-1
    def get_log(self):
        try:
            log_data = filewriter.get_log_file(self.name)
            log.logger.info(log_data)

            # 처음부터 진행
            if not log_data:
                self.process_count = 0
                self.result_list = []
            else:
                self.process_count = log_data[0]
                self.result_list = log_data[1]
            return True
        except:
            self.process_count = 0
            self.result_list = []

            return False
コード例 #16
0
    def login(self):
        try:
            account_data = filewriter.get_log_file(self.name + '_account')

            if account_data is None:
                raise Exception('Login account info can not be founded.')

            # 로그인 버튼 클릭
            if self.selenium_click_by_xpath(tag={
                    'tag': 'div',
                    'attr': 'class',
                    'name': 'login_request_btn'
            }) is False:
                raise Exception('selenium_extract_by_xpath fail.')

            if self.selenium_input_text_by_xpath(text=account_data[0],
                                                 tag={
                                                     'tag': 'input',
                                                     'attr': 'name',
                                                     'name': 'user_id'
                                                 }) is False:
                raise Exception(
                    'selenium_input_text_by_xpath fail. gnb_userid')

            if self.selenium_input_text_by_xpath(text=account_data[1],
                                                 tag={
                                                     'tag': 'input',
                                                     'attr': 'name',
                                                     'name': 'password'
                                                 }) is False:
                raise Exception(
                    'selenium_input_text_by_xpath fail. gnb_password')

            if self.selenium_click_by_xpath(tag={
                    'tag': 'li',
                    'attr': 'class',
                    'name': 'log_btn'
            }) is False:
                raise Exception('selenium_extract_by_xpath fail.')

        except Exception as e:
            log.logger.error(e, exc_info=True)
コード例 #17
0
ファイル: success.py プロジェクト: ko9ma7/crawler-1
    def start(self):
        try:
            self.log = filewriter.get_log_file(self.name)
            today = datetime.today().strftime('%Y_%m_%d')
            yesterday = (datetime.today() - timedelta(1)).strftime('%Y_%m_%d')

            log_yesterday = self.log[yesterday]
            log_today = self.log[today]

            for key in log_today.keys():
                if key in log_yesterday:
                    del log_yesterday[key]

            if log_yesterday and len(log_yesterday) > 0:
                text = ', '.join(map(str, log_yesterday.keys()))
                text = '발송실패 모듈: %s\n확인해주세요.' % text

                if text:
                    telegrambot.send_message(text, 'dev')

        except Exception as e:
            log.logger.error(e, exc_info=True)
コード例 #18
0
    def start(self):
        try:
            self.bestKeyword = filewriter.get_log_file('naverkeyword')

            for ke in self.bestKeyword:
                print(ke)
            
            exit()

            
            if self.connect(site_url=self.NAVER_SHOPPING, is_proxy=False, default_driver='selenium',
                        is_chrome=True) is False:
                raise Exception('site connect fail')

            self.keywords = []

            self.collect_Naverkeywordrelated()

            self.destroy()

        except Exception as e:
            log.logger.error(e, exc_info=True)
コード例 #19
0
    def start(self):
        try:
            self.log = filewriter.get_log_file(self.name)

            self.kind = 'rent'
            self.tab = '임대'
            self.DETAIL_URL = 'https://www.myhome.go.kr/hws/portal/sch/selectRsdtRcritNtcDetailView.do?pblancId='

            if self.connect(
                    site_url=
                    'https://www.myhome.go.kr/hws/portal/sch/selectRsdtRcritNtcView.do',
                    is_proxy=False,
                    default_driver='selenium',
                    is_chrome=False) is False:
                raise Exception('site connect fail')

            self.scan_page()

            self.kind = 'buy'
            self.tab = '공공분양'
            self.DETAIL_URL = 'https://www.myhome.go.kr/hws/portal/sch/selectLttotHouseDetailView.do?pblancId='

            if self.connect(
                    site_url=
                    'https://www.myhome.go.kr/hws/portal/sch/selectLttotHouseView.do',
                    is_proxy=False,
                    default_driver='selenium',
                    is_chrome=False) is False:
                raise Exception('site connect fail')

            self.scan_page()

            self.destroy()

        except Exception as e:
            log.logger.error(e, exc_info=True)
コード例 #20
0
ファイル: crawler.py プロジェクト: ko9ma7/crawler-1
 def __init__(self):
     # 기존 로그 가져오기
     self.name = self.__class__.__name__.lower()
     self.log = filewriter.get_log_file(self.name)
     self.driver = None
コード例 #21
0
    def login(self):
        try:
            self.PATH_USER_DATA = os.path.join(self.PATH_NAME,
                                               'driver/userdata_naver_jshk')

            if self.connect(site_url=self.DETAIL_URL,
                            is_proxy=False,
                            default_driver='selenium',
                            is_chrome=True) is False:
                raise Exception('site connect fail')

            self.get_cookie()

            if self.connect(site_url=self.DETAIL_URL,
                            is_proxy=False,
                            default_driver='selenium',
                            is_chrome=True) is False:
                raise Exception('site connect fail')

            # 로그인 여부 체크
            try:
                if self.selenium_extract_by_xpath(tag={
                        'tag': 'a',
                        'attr': 'data-nclicks-code',
                        'name': 'orddel.new'
                }) is True:
                    log.logger.info('Alreday logined.')
                    return True
            except:
                pass

            # 계정정보 가져오기
            account_data = filewriter.get_log_file('naver_account_jshk')

            if account_data:
                self.driver.save_screenshot('smartstore_screenshot.png')

                # 로그인 페이지로 이동
                if self.selenium_click_by_xpath(
                        tag={
                            'tag': 'a',
                            'attr': 'data-nclicks-code',
                            'name': 'main.sellerlogin'
                        }) is False:
                    raise Exception('selenium_click_by_xpath fail. submit')

                if self.selenium_click_by_xpath(
                        tag={
                            'tag': 'a',
                            'attr': 'data-nclicks-code',
                            'name': 'login.nidlogin'
                        }) is False:
                    raise Exception('selenium_click_by_xpath fail. submit')

                if self.selenium_extract_by_xpath(tag={
                        'tag': 'input',
                        'attr': 'name',
                        'name': 'id'
                }) is False:
                    raise Exception('selenium_extract_by_xpath fail.')

                # 아이디 입력
                if self.selenium_input_text_by_xpath(text=account_data[0],
                                                     tag={
                                                         'tag': 'input',
                                                         'attr': 'name',
                                                         'name': 'id'
                                                     }) is False:
                    raise Exception(
                        'selenium_input_text_by_xpath fail. username')

                # 비번 입력
                if self.selenium_input_text_by_xpath(text=account_data[1],
                                                     tag={
                                                         'tag': 'input',
                                                         'attr': 'name',
                                                         'name': 'pw'
                                                     }) is False:
                    raise Exception(
                        'selenium_input_text_by_xpath fail. password')

                # 로그인 유지
                if self.selenium_click_by_xpath(
                        xpath='//*[@id="label_login_chk"]') is False:
                    raise Exception('selenium_click_by_xpath fail. login_chk')

                # 로그인 버튼 클릭
                if self.selenium_click_by_xpath(tag={
                        'tag': 'input',
                        'attr': 'type',
                        'name': 'submit'
                }) is False:
                    raise Exception('selenium_click_by_xpath fail. submit')

                try:
                    # 기기등록 함
                    if self.selenium_exist_by_xpath(
                            xpath='//*[@id="frmNIDLogin"]/fieldset/span[1]/a'
                    ) is True:
                        self.selenium_click_by_xpath(
                            xpath='//*[@id="frmNIDLogin"]/fieldset/span[1]/a')

                    # 로그인 상태유지
                    if self.selenium_exist_by_xpath(
                            xpath='//*[@id="login_maintain"]/span[1]/a'
                    ) is True:
                        if self.selenium_click_by_xpath(
                                xpath='//*[@id="login_maintain"]/span[1]/a'
                        ) is False:
                            raise Exception(
                                'selenium_click_by_xpath fail. submit')
                except:
                    pass

                log.logger.info('login success')
                self.set_cookie()

                sleep(2)

                return True
        except Exception as e:
            log.logger.error(e, exc_info=True)
            self.destroy()
            exit()

        return False
コード例 #22
0
ファイル: yoona_azzi.py プロジェクト: ko9ma7/crawler-1
    def start(self):
        try:
            # 프록시
            count = 0

            if self.TEST == False:
                proxy = Proxy()
                self.ips = proxy.get()
                self.ips_index = 0

                if self.ips == False:
                    log.logger.info('proxy ip empty')
                    exit()
                log.logger.info(', '.join(self.ips))

            # print(self.ips)
            # exit()

            self.log = filewriter.get_log_file(self.name)
            date_now = datetime.now(timezone('Asia/Seoul'))
            self.today = date_now.strftime('%Y-%m-%d')
            self.yesterday = (date_now -
                              timedelta(days=1)).strftime('%Y-%m-%d')
            self.data = filewriter.get_log_file('yoonaazzi_data', is_json=True)

            for apt, id in self.DETAIL_URL.items():
                count = count + 1

                # 아파트별로 페이지 초기화
                self.page = 1
                exists = False

                # 첫아파트라면 초기화
                for apted in self.data.keys():
                    if apted == apt:
                        apt = apted
                        exists = True

                if exists == False:
                    print('없음')
                    self.data[apt] = {}

                # 오늘 데이터가 있다면 continue
                try:
                    if self.today in self.data[apt].keys():
                        log.logger.info('%s today exists.' % (apt))
                        continue
                except:
                    pass

                log.logger.info('%s collecting start...(%d/%d)' %
                                (apt, count, len(self.DETAIL_URL)))

                self.total_prices_complete = 0
                self.total_jeonses_complete = 0
                self.total_prices = 0
                self.total_jeonses = 0
                self.prices = {}
                self.prices_filter = {}
                self.jeonses = {}
                self.jeonses_filter = {}

                # 어제 데이터가 있다면 어제 데이터로 초기세팅 (0값을 없애기 위해)
                if self.yesterday in self.data[apt]:
                    if 'prices' in self.data[apt][self.yesterday]:
                        # 데이터만 복사 (참조하지 않도록)
                        self.prices_filter = self.data[apt][
                            self.yesterday]['prices'].copy()

                try:
                    # 가격 수집
                    while 1:
                        if self.collect_price(apt=apt, id=id) == False:
                            break

                    if self.total_prices == 0 and self.total_jeonses == 0:
                        continue

                    # 가격 필터
                    self.filter_price(apt=apt, id=id)

                    # 로그 저장
                    self.set_log(apt=apt)

                    sleep(round(uniform(1.0, 3.0), 1))
                except:
                    pass

            # ** 모든 아파트 수집 완료 **

            # 오늘의 데이터 저장
            filewriter.save_log_file('yoonaazzi_data', self.data)

            log.logger.info('yoona_azzi complete.')

            exit()

        except Exception as e:
            log.logger.error(e, exc_info=True)
            exit()
コード例 #23
0
    def login(self):
        try:
            # 로그인 여부 체크
            if self.connect(site_url=self.UNFOLLOW_URL, is_proxy=False, default_driver='selenium', is_chrome=True) is False:
                raise Exception('site connect fail')

            self.get_cookie()

            if self.connect(site_url=self.UNFOLLOW_URL, is_proxy=False, default_driver='selenium',
                            is_chrome=True) is False:
                raise Exception('site connect fail')

            try:
                if self.selenium_exist_by_xpath(xpath='//*[@id="react-root"]/section/nav/div[2]/div/div/div[3]/div/span/a[1]/button') is False:
                    log.logger.info('Already loggined.')
                    return True
            except:
                pass

            # 로그인 되어있지 않다면 로그인 페이지로 이동
            if self.connect(site_url=self.LOGIN_URL, is_proxy=False, default_driver='selenium', is_chrome=True) is False:
                raise Exception('site connect fail')

            # 계정정보 가져오기
            account_data = filewriter.get_log_file(self.name + '_account')

            if account_data:
                if self.selenium_extract_by_xpath(tag={'tag': 'input', 'attr': 'name', 'name': 'username'}) is False:
                    raise Exception('selenium_extract_by_xpath fail.')

                # 아이디 입력
                if self.selenium_input_text_by_xpath(text=account_data[0], tag={'tag': 'input', 'attr': 'name', 'name': 'username'}) is False:
                    raise Exception('selenium_input_text_by_xpath fail. username')

                # 비번 입력
                if self.selenium_input_text_by_xpath(text=account_data[1], tag={'tag': 'input', 'attr': 'name', 'name': 'password'}) is False:
                    raise Exception('selenium_input_text_by_xpath fail. password')

                # 아이디 입력
                if self.selenium_input_text_by_xpath(text=account_data[0], tag={'tag': 'input', 'attr': 'name', 'name': 'username'}) is False:
                    raise Exception('selenium_input_text_by_xpath fail. username')

                # 비번 입력
                if self.selenium_input_text_by_xpath(text=account_data[1], tag={'tag': 'input', 'attr': 'name', 'name': 'password'}) is False:
                    raise Exception('selenium_input_text_by_xpath fail. password')

                # 로그인하기 선택
                if self.selenium_click_by_xpath(tag={'tag': 'button', 'attr': 'type', 'name': 'submit'}) is False:
                    raise Exception('selenium_click_by_xpath fail. submit')

                sleep(3)

                # 비정상적인 로그인 시도 처리 (내가 맞습니다)
                try:
                    if self.selenium_exist_by_xpath(xpath='//*[@id="react-root"]/section/div/div/div[3]/form/div[2]/span/button') is True:
                        self.selenium_click_by_xpath(xpath='//*[@id="react-root"]/section/div/div/div[3]/form/div[2]/span/button')
                except:
                    pass

                # 보안코드
                try:
                    if self.selenium_exist_by_xpath(xpath='//*[@id="react-root"]/section/div/div/div[1]/div/p') is True:
                        if self.selenium_exist_by_xpath(xpath='//*[@id="react-root"]/section/div/div/div[3]/form/span/button') is True:

                            # 보안코드가 없다면 block 처리해서 인스타그램 프로세스를 중지
                            if self.security_code[0] == '':
                                self.security_code[0] = 'blocked'
                                filewriter.save_log_file('instagram_security_code', self.security_code)
                                log.logger.info('Instagram has just blocked.')
                                telegrambot.send_message('Instagram has just blocked.', 'instagram')
                                self.destroy()
                                exit()

                            # 발송하기
                            self.selenium_click_by_xpath(xpath='//*[@id="react-root"]/section/div/div/div[3]/form/span/button')

                            # 텔레그램 알림
                            telegrambot.send_message('Please check instagram security code from your email in 1 minutes.', 'instagram')
                            log.logger.info('Please check instagram security code from your email in 1 minutes.')

                            # 수정될 때 까지 50초 대기
                            sleep(50)

                            # 새롭게 입력된 데이터를 가져옵니다.
                            self.security_code = filewriter.get_log_file('instagram_security_code')

                            # 보안코드 입력
                            if self.selenium_input_text_by_xpath(text=self.security_code[0], xpath='//*[@id="security_code"]') is False:
                                raise Exception('selenium_input_text_by_xpath fail. security_code')

                            # 제출
                            self.selenium_click_by_xpath(xpath='//*[@id="react-root"]/section/div/div/div[2]/form/span/button')

                            log.logger.info('security_code. (%s)' % (self.security_code[0]))

                            # 사용한 코드는 제거
                            self.security_code[0] = ''
                            filewriter.save_log_file('instagram_security_code', self.security_code)

                            sleep(5)

                except Exception as e:
                    log.logger.error(e, exc_info=True)
                    pass

                try:
                    if self.selenium_exist_by_xpath(xpath='//*[@id="react-root"]/section/nav/div[2]/div/div/div[3]/div/div/div/div/div[3]/div[1]/a') is True:
                        log.logger.info('login fail.')
                        raise Exception('login fail error')
                except:
                    pass

                log.logger.info('login success!')

                self.set_cookie()

                sleep(2)

                return True
        except Exception as e:
            log.logger.error(e, exc_info=True)
            self.end_report()

        return False
コード例 #24
0
    def scan_page(self):
        try:
            if self.FAIL_CNT > 3:
                raise Exception('Block error')

            if self.connect(site_url=self.TAG_URL + self.tag[0] + '/', is_proxy=False, default_driver='selenium', is_chrome=True) is False:
                raise Exception('site connect fail')

            if self.selenium_extract_by_xpath(tag={'tag': 'div', 'attr': 'class', 'name': 'EZdmt'}) is False:
                raise Exception('selenium_extract_by_xpath fail.')

            # 상단의 인기게시글 (최대 9개)
            list = self.driver.find_element_by_xpath("//div[@class='EZdmt']").find_elements_by_xpath('.//div[contains(@class,"v1Nh3")]/a')

            for li in list:
                try:
                    self.is_need_sleep = False

                    # 레이어 열기
                    li.click()

                    # 레이어 기다림
                    if self.selenium_extract_by_xpath(xpath='//article[contains(@class,"M9sTE")]') is False:
                        raise Exception('selenium_extract_by_xpath fail.')

                    # 채널명
                    target_name = self.driver.find_element_by_xpath('//article[contains(@class,"M9sTE")]/header/div[2]/div[1]/div[1]/h2/a')
                    if target_name:
                        self.TARGET_NAME = target_name.text

                    # 사용할 댓글이 없다면 수집만 먼저
                    if len(self.REPLY) == 0:
                        self.reply_collect()
                        self.selenium_click_by_xpath(xpath='//button[contains(@class,"ckWGn")]')
                        continue

                    if self.like() is True:
                        self.follow()
                        self.reply_collect()
                        self.reply_send()

                    # 작업이 있었다면 block을 피하기 위해 sleep
                    if self.is_need_sleep is True:
                        #sleep_second = random.randint(180, 200)
                        sleep_second = random.randint(50, 60)
                        #log.logger.info('sleeping.. %d' % (sleep_second))
                        sleep(sleep_second)
                        self.is_need_sleep = True

                    # 레이어 닫기
                    self.selenium_click_by_xpath(xpath='//button[contains(@class,"ckWGn")]')

                except Exception as e:
                    log.logger.error(e, exc_info=True)
                    self.FAIL_CNT = self.FAIL_CNT + 1

                    break

            self.tag.pop(0)
            filewriter.save_log_file('instagramcollecttag_copied', self.tag)

            self.CRITICAL_CNT = 0

            # 팔로우 100개 마다 브라우저 리셋
            duration = int((datetime.now() - self.starttime).total_seconds() / 60)
            # print(duration)
            # 10분 동안 작업 했다면 종료
            if duration > 10:
            # if (self.FOLLOW_CNT > 5):
                return True

            if len(self.tag) > 0:
                self.scan_page()

        except Exception as e:
            self.CRITICAL_CNT = self.CRITICAL_CNT + 1
            log.logger.error(e, exc_info=True)

            # 태그 삭제
            tag_copy = filewriter.get_log_file('instagramcollecttag_copied')
            if tag_copy:
                tag_copy.remove(self.tag[0])
                filewriter.save_log_file('instagramcollecttag_copied', tag_copy)

            tag = filewriter.get_log_file('instagramcollecttag')
            if tag:
                tag.remove(self.tag[0])
                filewriter.save_log_file('instagramcollecttag', tag)

            self.end_report()