def insta_mobile_work(device, max_work): links = read_links() print(links) cnt = 1 for link in links: if cnt >= max_work: print(link) print("이제 작업 종료하겠습니다") break try: visited_links = [] # 이미 좋아요, 댓글, 팔로우를 신청한 링크 리스트 with open('visited.txt', 'r') as f: while True: line = f.readline() if not line: break _link = line.rstrip() visited_links.append(_link) if link in visited_links: print("이미 방문한 링크입니다.") continue print(f"{cnt} 번째 링크 방문 {link}") # link = link.replace("https://","") device.press('home') device.open_url(link) time.sleep(0.2) if device(text="작업을 수행할 때 사용하는 애플리케이션").exists(timeout=2): # 삭제되었거나, 잘못된 URL 저장된 경우에 continue continue ''' visited_account check 목표 : 최대 3회까지 계정 방문하는 기능 ''' visited_accounts = [] with open('./visited_account.txt', "r") as f: while True: line = f.readline() if not line: break account = line.rstrip() visited_accounts.append(account) # 몇 번 방문했는지 정보 획득 account_id = device(resourceId="com.instagram.android:id/row_feed_photo_profile_name").get_text() visited_count = visited_accounts.count(account_id) if visited_count >= 3: # 3회 이상 방문일 때는 다음 링크를 방문하도록 한다 # continue가 실행되면 여기 밑에있는 코드가 실행이 안됨 (for 문 안에서 사용가능) continue ''' 1. 좋아요 누르기 - 단, 좋아요가 이미 눌러져 있으면 Pass ''' # 좋아요 버튼 나타나는것 기준으로 5초까지 대기 if not device(resourceId="com.instagram.android:id/row_feed_button_like").exists(timeout=3): device.swipe_ext("up", scale=0.75) time.sleep(3) alreadyLiked = False if device(resourceId="com.instagram.android:id/row_feed_button_like").exists( timeout=5): # 만약 ,좋아요 버튼이 안 눌러져있으면 좋아요 버튼을 누른다 if device(resourceId="com.instagram.android:id/row_feed_button_like", selected=False): device(resourceId="com.instagram.android:id/row_feed_button_like").click() time.sleep(1) if check_bot_detection(device): print("[봇 탐지] - 좋아요 시도 실패") raise Exception("[봇 탐지] - 좋아요 시도 실패") else: alreadyLiked = True time.sleep(3) # ''' # 2. 댓글 달기 - 랜덤 멘트를 미리 작성해놓고, 랜덤으로 뽑아서 댓글 달기''' # if not alreadyLiked: # device(resourceId="com.instagram.android:id/row_feed_button_comment").click() # time.sleep(3) # # 기본 키보드가 활성화 되어있는 경우 back버튼을 눌러줌 # if device(resourceId="com.samsung.android.honeyboard:id/bee_item_icon").exists(): # device.press('back') # time.sleep(1) # if not device(text="이 게시물에 대한 댓글 기능이 제한되었습니다.").exists(): # print("커멘트 작성 가능 exists") # device(resourceId="com.instagram.android:id/layout_comment_thread_edittext").click() # # 실제 사람이 작성하는 것처럼 문장 사이의 타이핑 딜레이가 들어감 # comments = ["♡", "❤️", "❤️❤️", "♥"] # comment = random.choice(comments) # for word in comment: # device.send_keys(word) # time.sleep(random.uniform(0.03, 0.08)) # print("댓글 작성 완료") # time.sleep(3) # if device( # resourceId="com.instagram.android:id/layout_comment_thread_post_button_click_area").exists(): # device( # resourceId="com.instagram.android:id/layout_comment_thread_post_button_click_area").click() # elif device(resourceId="com.instagram.android:id/layout_comment_thread_post_button").exists(): # device(resourceId="com.instagram.android:id/layout_comment_thread_post_button").click() # time.sleep(1) # if check_bot_detection(device): # print("[봇 탐지] - 댓글 달기 시도 실패") # raise Exception("[봇 탐지] - 댓글 달기 시도 실패") # print("게시 버튼 꾸욱.") # time.sleep(2) # device.press('back') # time.sleep(2) # device.press('back') # else: # device.press('back') # time.sleep(3) # 방문 1회 추가 ! with open('./visited_account.txt', "a") as f: f.write(f"{account_id}\n") # 3. 팔로우 신청 - 단, 이미 팔로잉 상태면 Pass # 사진 사이즈가 너무 크면, 위로 스와이프 해줘야함 device.swipe_ext("down", scale=0.8) time.sleep(3) account_ids = [] # 이미 팔로우를 신청한 계정 리스트 with open('accounts.txt', "r") as f: while True: line = f.readline() if not line: break account_id = line.rstrip() account_ids.append(account_id) if not device(resourceId="com.instagram.android:id/row_feed_photo_profile_name").exists(): device.press('back') time.sleep(1) target_account_id = device(resourceId="com.instagram.android:id/row_feed_photo_profile_name").get_text() # 딱 1번만 팔로우 하겠다. if not target_account_id in account_ids: # 팔로우할 유저의 계정을 기록 with open('accounts.txt', "a") as f: account_id = device(resourceId="com.instagram.android:id/row_feed_photo_profile_name").get_text() f.write(f"{account_id}\n") device(resourceId="com.instagram.android:id/row_feed_photo_profile_name").click() time.sleep(3) if device(description="맞팔로우 하기", text="맞팔로우").exists(): device(description="맞팔로우 하기", text="맞팔로우").click() elif device(text="팔로우", className="android.widget.Button"): device(text="팔로우", className="android.widget.Button").click() else: # 이미 맞 팔로우가 되어 있으므로 실행시키지 않아도 됨 pass time.sleep(1) if check_bot_detection(device): print("[봇 탐지] - 팔로우, 맞팔로우 신청 시도 실패") raise Exception("[봇 탐지] - 팔로우, 맞팔로우 신청 시도 실패") time.sleep(2) device.press("back") time.sleep(2) device.press("back") time.sleep(3) else: print("이미 팔로우된 계정입니다") cnt += 1 random_time = random.randrange(60, 90) print(random_time, '초만큼 대기하겠습니다') time.sleep(random_time) '좋아요, 팔로우, 댓글 작성까지 완료된 게시글' with open('visited.txt', 'a') as f: f.write(f"{link}\n") except: pass 1 번째 링크 방문 https://www.instagram.com/p/C2DUpJJBWI1/ 1 번째 링크 방문 https://www.instagram.com/p/C3SMeJSyIRC/ 1 번째 링크 방문 https://www.instagram.com/p/C3fDCYiM4gt/ 1 번째 링크 방문 https://www.instagram.com/p/C2hjVjmxPEg/ 왜그런가요?
안녕하세요 유튜브도 보고, 강의도 결제해서 보고 있는 이광희라고 합니다. 강의 정말 감사드립니다. 강의대로 코드 짰더니 봇에 전송도 잘 되는데 문제는 메세지가 길어져서 (업무특성상 뉴스 검색량이 많음) 4,096바이트를 넘어가니 전송이 아얘 되지를 않네요. 일반적인 텔레그램 1:1채팅이나 단체방 채팅에서는 장문을 입력하면 자동으로 나눠져서 전송되는데 API는 4,096바이트가 넘어가니 아얘 전송이 되질 않네요. 1) 이걸 코딩에서 해결해서 전송해야 한다면 어떤 방법이 있을지 2) 아니면 텔레그램 API상 다른 방법이 있는지요 궁금합니다
폰에 atx라는 자동차 모양 아이콘의 앱이 설치되었어요. 얘가 전화 허용이라는 권한을 요청하기도 했고 폰 상단 알림창에 계속 uiautomator 이라는 이름과 ip주소가 써진 알람을 계속 보내요 . 알람을 지우고 몇 분 뒤에 보면 또 알람창에 떠 있고. 이 앱을 폰에 계속 설치되어 있는 상태로 있어야 하는지 궁금합니다. 앱 들어가보면 weditor처럼 중국어(?)로 써져 있어서 불안해서요.
강사님 매번 강의로 도움많이받고있습니다 감사합니다. 개인적으로 일전에 구글을 예를 들어 다양한 키워드에 따라 생성 텝메뉴들이 달라져서 고민을 많이하던때가있었는데 'View탭 클릭하여 페이지넘어가기'강의와 같이 xpath 지정하였을때 '//*[text()="VIEW"]' 입력하면 되는것일까요? 음 현재 네이버가 뷰 서비스를 폐지했는데 만약 블로그를 클릭한다면 '//*[text()="블로그"]' 를 입력하면 클릭이되나요?안되서여ㅜㅜ혹시 도움이될만한 고견주시면 감사드리겠습니다.
undetected chromedriver 를 사용할때 UA_Data = make_user_agent(UA, True) self.driver.execute_cdp_cmd("Network.setUserAgentOverride", UA_Data) 를 이용하여도 userAgentData의 변경이 되지 않습니다. 버전의 문제일까요?
안녕하세요. 4. CDP Command 종류 많죠? 잘 정리된 사이트 소개해드림 부분 강의 듣고있습니다. 파란 사이트, 초록 사이트 주소 알려주신다고 했는데 어디에 나와있나요? 그리고 문서에서 어떤 걸 저희가 능동적으로 찾아야 하고 어떻게 읽고 적용하는지도 알려주시면 좋겠습니다. 필요한 걸 저희가 직접 찾고 적용하는 방법을 알려주셔야 하는데 그냥 코드만 알려주시니까 저희 상황에 맞게 수정하는 방법을 모르겠습니다. 문서를 활용해서 저희에게 어떤 속성이 필요한지 찾는 방법도 자세히 알려주시면 감사하겠습니다. Emulation 이랑 Network랑 뭐가 다른지도 모르겠어요. setDeviceMetricsOverride 가 왜 필요한건진 알겠는데 이 속성이 필요하다는 걸 아는 방법은 모르겠어요. 즉 물고기를 잡아주기만 하는 게 아니라 잡는 방법을 알려주셨으면 합니다.
안녕하세요. ch 2-2 User Agent Data 변경하는법 강의에서 10:00, 10:09 에 '내 눈으로 본것만 믿읍시다' 자막 부분 이해가 안갑니다. Not?A_Brand는 version 끝자리 숫자로 바뀌었네요 이게 무슨 뜻인가요? version last string 값을 넣어주시죠 version 110 되었을때는 0이 될지 10이 될지 그거는 그때 확인해야할듯함 이거는 무슨 뜻일까요?? 강의 보다보면 이렇게 추가적으로 중간중간 자막 달아주신것들이 이해가 안되는 것들이 많습니다. 맥락을 충분히 설명 안해주시고 말씀하시는 느낌이 든달까... 조금만 더 자세히 설명해주시면 감사하겠습니다 ㅜㅜ --------------- 추가로, 이 강의에선 undetected_chromedriver 를 사용하지 않고 일반 웹드라이버를 사용하셨는데 undetected 드라이버랑 함께 사용하지 않으신 이유가 뭘까요??
글에 두서가 없어도 양해 바랍니다 이 수업 수강 이전에 코딩 문제를 풀 때 파이썬으로 재귀함수를 사용했던 적이 있습니다. 그때 알게 된것이 파이썬의 재귀함수에는 기본적으로 깊이의 제한이 있다는 것입니다. sys.recursionlimit()으로 확인해보니 재귀호출을 1000이상 못하도록 값이 제한되어 있고 이 값을 늘려서 사용하는것은 별로 추천되는 방법이 아닌걸로 알고 있습니다. C언어 사용할때에는 속도면에서 제한도 없고 파이썬보다 속도도 월등하다보니 재귀를 자주 사용했었는데 파이썬에서 재귀함수로 풀어야 하는 경우가 있을까요?
age_bin_list = np.arange(10, 80, 10) df['age_bin'] = pd.cut(df['age'], bins = age_bin_list) pivot_df = df.pivot_table( index = 'age_bin', columns = 'region', values = 'charges', aggfunc = 'median' # 각 구간에 해당하는 값을 중간값을 사용하겠다. ) pivot_df # 각각의 값들에 대해 크기를 가늠할 수 있게끔 시각화(주로 색상)하는 방법 # 2D 형식으로 준비된 데이터를 Seaborn heatmap으로 시각화 # annot 인자를 통해 각 셀의 값 표현 가능 fig, ax = plt.subplots() sns.heatmap(pivot_df, ax = ax, annot = True) 코드 똑같이 따라했는데 왜 저는 표에 수치가 다 표현이 안되는 건가요?
import requests from bs4 import BeautifulSoup url = "https://search.naver.com/search.naver?where=view&sm=tab_jum&query=" keyword = input("검색어를 입력하세요: ") url = url + keyword print(url) #개발자 도구 > 네트워크 > www.naver.com > 요청 헤더 > user-gent headers = { "User-Agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" } req = requests.get(url, headers=headers) html = req.text soup = BeautifulSoup(html, "html.parser") # 게시물별 view 구역 total_area = soup.select(".view_wrap") rank_num= 1 for area in total_area: ad = area.select_one(".link_ad") if ad: continue print(f"<<<{rank_num}>>>") title = area.select_one(".title_area") name = area.select_one(".name") href = area.select_one(".title_link") print(title.text) print(name.text) # print(title["href"] print(href["href"]) print() rank_num += 1 <에러 문구> line 41, in <module> print(title["href"]) File "/User/opt/anaconda3/envs/edu/lib/python3.9/site-packages/bs4/element.py", line 1573, in getitem return self.attrs[key] KeyError: 'href' 안녕하세요, 수업 잘 듣고 있습니다. 저도 블로그 링크를 바로 가져오고 싶어서 print(title["href"]로 가져오려 했으나 keyError가 발생합니다. 우선 대안으로, href 변수를 반들고 따로 링크만 가져올 수 있는 코드를 추가하긴 하였으나 왜 키 에러가 발생하여 print(title["href"]로 링크를 바로 못 가져 오는 것인지가 궁금합니다.
안녕하세요 강사님 ㅎㅎ 현재 챕터도 이전과 같은 증상인데 어떻게 확인하면 좋을까요? Github snapshot: https://github.com/dimz119/learn-python-django/tree/form_view 에서 다운받아서 실행시켜도 제가 작성한 코드랑 똑같은 문제가 발생하는데 확인할수있는 방법이있을까요??