Closed ghost closed 1 year ago
Are you using GetMessager() or BotStart()? And it doesn't return any kind of error?
I use it without changing. Botstart(). It doesn't return anything as text is empty that cause infinite loop. I also used different username, and got another error that closes the pages when message section is clicked.
GetMessager() for my understanding is not applied anywhere
Are you passing the parameters in the correct order? First comes the username and then the APIKEY. Getting like this:
python InstagramBot.py <user> <apikey>
I've just tested the bot here, and it's still working normally. Try putting some prints() to get the value of USER and API_KEY variables and then check if the user is passed correctly, as well as the APIKEY.
if __name__ == "__main__":
if len(sys.argv) < 3:
raise Exception("USER and API_KEY is mandatory and must be passed as an argument.")
USER = sys.argv[1]
API_KEY = sys.argv[2]
print("Instagram User: ", USER)
print("API_KEY: ", API_KEY)
BotGPT = ChatBot(API_KEY)
InstBOT = InstagramBotGPT(user=USER, chatbot=BotGPT)
InstBOT.BotStart()
No, unfortunately, I already used it in this way. I have used it on three PCs (mac and windows), it didn't work out. Which google chrome version you used?
I use version 106.0.5249.103. Does your browser simply close or is the bot unable to respond? Maybe instagram is different in your region. Can you send a screenshot of the steps or where the script break?
I use 109 version. The bot doesn’t find any text. I’ve printed it out but the result is “[]”
And one more question; is there a way to create a chatbot that can communicate with my insta friends if they send message. I guess we need to use InstaAPI for that
Sent from my iPhone
On 22 Feb 2023, at 19:18, José Henrique Siqueira @.***> wrote:
I use version 106.0.5249.103. Does your browser simply close or is the bot unable to respond? Maybe instagram is different in your region. Can you send a screenshot of the steps or where the script break?
— Reply to this email directly, view it on GitHubhttps://github.com/JoseHenriqueSiqueira/Whatsapp_Instagram_Messanger_ChatGPT_OpenAI/issues/3#issuecomment-1440660703, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AIMFH4K2FGHYJ6TKZKYNCY3WYZRBJANCNFSM6AAAAAAVDCGVRE. You are receiving this because you authored the thread.Message ID: @.***>
can you open the script and try to use the getmessanger method? it is exactly for debug. It will check if it is capturing user or author messages.
if __name__ == "__main__":
InstBOT = InstagramBotGPT(user='type_any_user_here', chatbot=None)
author_msg = InstBOT.GetMessager('author')
user_msg = InstBOT.GetMessager('user')
print("\nAUTHOR_MESSAGES:", author_msg)
print("\nUSER_MESSAGES:", user_msg)
That way you don't need to pass the parameters. Try using it like this and check if any of the variable values are printed:
python InstagramBot.py
By the way, check that the user is correct with the Instagram one. User example: https://www.instagram.com/user123/. so, copy 'user123'.
About your second question: Yes, that's the purpose of the bot itself. You enter a target user as a parameter and then the conversation is captured in a loop. After the target user sends a message, the script captures this message and stores it in a variable and then sends it to the Bot. When the bot returns the answer, then it is passed to the element responsible for sending messages on instagram and finally it is sent to the target user through the simulation of the Enter key.
Yes, I have tried it and it gives empty text and It did not open messages at all.
And this is the output after the page is closed automatically.
AUTHOR_MESSAGES: []
USER_MESSAGES: []
I guess the problem is related to BY.CLASS_NAME. I will also search this out to capture the texts. Thanks for the debugging clue.
For the second question, I was meaning that a more autonomous way to do that without entering the target name. E.g. Just the author username is entered and the bot is alive. So it can answer whoever asks a question.
Can you provide me with the full version of chrome you are trying? So I add it to the repository that is malfunctioning with that specific version.
About your question about the bot, yes it is possible. With a little web scraping you can do it. I would try as follows. 1 - Ask some users to send a message to your account. 2 - Then you will inspect the elements and look for what differs an element that contains unread messages, to an element that contains a read message. Possibly a different specific class. 2 - look for the class responsible for the users' messages. 3 - and the rest is basically already in the InstagramBot. Hope this helps you.
Version 110.0.5481.100, I am not sure if it is related to a google chrome version though. Thanks anyway for your comments.
I think it's some version of Instagram. I could fix it for you, I'll try to find an alternative class to get the text.
Version 110.0.5481.100, I am not sure if it is related to a google chrome version though. Thanks anyway for your comments.
I've updated the repository and added selinium functionality that waits for the element to be loaded before proceeding. Perhaps the problem was that your script ran before the class itself loaded. Try using prints() again in GetMessager()
File "/Users/erdogan/PycharmProjects/Whatsapp_Instagram_Messanger_ChatGPT_OpenAI/InstagramBot.py", line 66, in <module>
author_msg = InstBOT.GetMessager('author')
File "/Users/erdogan/PycharmProjects/Whatsapp_Instagram_Messanger_ChatGPT_OpenAI/InstagramBot.py", line 50, in GetMessager
self.wait.until(EC.presence_of_element_located((By.CLASS_NAME, UserType)))
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/support/wait.py", line 95, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
Stacktrace:
0 chromedriver 0x000000010ad98138 chromedriver + 4923704
1 chromedriver 0x000000010ad109d3 chromedriver + 4368851
2 chromedriver 0x000000010a959787 chromedriver + 472967
3 chromedriver 0x000000010a99dba3 chromedriver + 752547
4 chromedriver 0x000000010a99ddf1 chromedriver + 753137
5 chromedriver 0x000000010a9e4734 chromedriver + 1042228
6 chromedriver 0x000000010a9c6fdd chromedriver + 921565
7 chromedriver 0x000000010a9e1c0f chromedriver + 1031183
8 chromedriver 0x000000010a9c6d23 chromedriver + 920867
9 chromedriver 0x000000010a98da4b chromedriver + 686667
10 chromedriver 0x000000010a98f044 chromedriver + 692292
11 chromedriver 0x000000010ad638fe chromedriver + 4708606
12 chromedriver 0x000000010ad68e22 chromedriver + 4730402
13 chromedriver 0x000000010ad716bf chromedriver + 4765375
14 chromedriver 0x000000010ad69e80 chromedriver + 4734592
15 chromedriver 0x000000010ad3a975 chromedriver + 4540789
16 chromedriver 0x000000010ad8be78 chromedriver + 4873848
17 chromedriver 0x000000010ad8bff5 chromedriver + 4874229
18 chromedriver 0x000000010ada06de chromedriver + 4957918
19 libsystem_pthread.dylib 0x00007fff6bc3e109 _pthread_start + 148
20 libsystem_pthread.dylib 0x00007fff6bc39b8b thread_start + 15
I am receiving this now. It exceeds the wait time. I think the problem is the same. For some reason, BY.class_name does not get the text from the inspected class.
Problem solved. I accidentally changed the user by refoctoring Types = {"author":"_acqv", 'user':'_acqu'} with an instagram user name
Now both methods are working and returning messages?
Yes, I can receive both messages. Also, another problem was stemming from when author and username is same.
sometime it doesn’t recognise some usernames such as my fake account e.g “user1234” as user. But when I enter my fake account as author it works
Sent from Outlook for iOShttps://aka.ms/o0ukef
From: José Henrique Siqueira @.> Sent: Friday, February 24, 2023 1:09:50 AM To: JoseHenriqueSiqueira/Whatsapp_Instagram_Messanger_ChatGPT_OpenAI @.> Cc: Vural Erdogan @.>; State change @.> Subject: Re: [JoseHenriqueSiqueira/Whatsapp_Instagram_Messanger_ChatGPT_OpenAI] self.driver.find_elements returns with [] can't find the text (Issue #3)
Now both methods are working and returning messages?
— Reply to this email directly, view it on GitHubhttps://github.com/JoseHenriqueSiqueira/Whatsapp_Instagram_Messanger_ChatGPT_OpenAI/issues/3#issuecomment-1442651404, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AIMFH4KGOWN4BNLF5YUWKZLWZAC55ANCNFSM6AAAAAAVDCGVRE. You are receiving this because you modified the open/close state.Message ID: @.***>
Right. This issue has been resolved. The other problem I will study a little what could be the cause and simulate some scenarios
instagrambot.py messages_element = self.driver.find_elements(By.CLASS_NAME, username) does not return as expected. Therefore, the codes are stuck in while loop as there is no message