• 카테고리

    질문 & 답변
  • 세부 분야

    업무 자동화

  • 해결 여부

    미해결

섹션6-3 '댓글' 질문드립니다!

23.05.31 19:04 작성 조회수 242

1

섹션 6-3에서 for word in "멘트" <<

이렇게 돌리면 댓글이 한글자씩 입력하고 작성됩니다.

ex) 멘트

댓글1 : 멘 댓글2 : 트

if not device(text="이 게시물에 대한 댓글 기능이 제한되었습니다.").exists(): print("커멘드 작성 가능 exists") device(resourceId="com.instagram.android:id/layout_comment_thread_edittext").click()

for word in "안녕하세요!": device.send_keys(word) time.sleep(random.uniform(0.03,0.08)) time.sleep(5) device(resourceId="com.instagram.android:id/layout_comment_thread_post_button_click_area").click() time.sleep(2) device.press('back') time.sleep(2) device.press('back')

 

if not device(text="이 게시물에 대한 댓글 기능이 제한되었습니다.").exists():         print("커멘드 작성 가능 exists")         device(resourceId="com.instagram.android:id/layout_comment_thread_edittext").click()         

 for word in "안녕하세요!":             device.send_keys(word)             time.sleep(random.uniform(0.03,0.08))             time.sleep(5)               device(resourceId="com.instagram.android:id/layout_comment_thread_post_button_click_area").click()             time.sleep(2)             device.press('back')             time.sleep(2)             device.press('back')     

답변 2

·

답변을 작성해보세요.

1

if not device(text="이 게시물에 대한 댓글 기능이 제한되었습니다.").exists():         
    print("커멘드 작성 가능 exists")
    device(resourceId="com.instagram.android:id/layout_comment_thread_edittext").click()         

    for word in "안녕하세요!":
        device.send_keys(word)
        time.sleep(random.uniform(0.03,0.08))
        time.sleep(5)
        time.sleep(2)
        device.press('back')
        time.sleep(2)
        device.press('back') 

    device(resourceId="com.instagram.android:id/layout_comment_thread_post_button_click_area").click()


위 코드로 변경하시면 작동될거에요 !

1

인프런 AI 인턴님의 프로필

인프런 AI 인턴

2023.06.02

안녕하세요, 인프런 AI 인턴이에요.

질문 내용을 보니, 인스타그램 댓글 작성 코드를 작성하시려는 것으로 보입니다. for문에서 “멘트” 대신 “안녕하세요!“를 입력했을 때 댓글이 한글자씩 입력되는 문제가 발생하는 것으로 이해하였습니다.

이 경우, for문이 “안녕하세요!“에서 한 글자씩 반복되기 때문에, 매 반복마다 한 글자씩 입력되는 것 같아요. 이를 해결하려면, “안녕하세요!” 전체를 send_keys의 인자로 넣어서 한 번에 입력하도록 코드를 작성하면 될 것 같습니다.

아래는 수정된 코드 예시입니다.

if not device(text=“이 게시물에 대한 댓글 기능이 제한되었습니다.”).exists():
print(“커멘드 작성 가능 exists”)
device(resourceId=“com.instagram.android:id/layout_comment_thread_edittext”).click()
device.send_keys(“안녕하세요!”)
time.sleep(random.uniform(0.03,0.08))
time.sleep(5)
device(resourceId=“com.instagram.android:id/layout_comment_thread_post_button_click_area”).click()
time.sleep(2)
device.press(‘back’)
time.sleep(2)
device.press(‘back’)

다음과 같이 코드를 작성하시면, “안녕하세요!” 전체가 한번에 입력되어 댓글 작성이 가능할 것입니다.

아직도 문제가 발생한다면, 인스타그램 앱의 업데이트나 환경 설정 등을 다시 확인해보시는 것도 좋을 것 같아요. 감사합니다.