Giter VIP home page Giter VIP logo

Comments (16)

Radulepy avatar Radulepy commented on August 13, 2024 1

Hi,

So the problem with this bot is that it has to be changed with every Instagram update.
Your error (line 66) is searching for the username field. You can find the X path of the field by going to instagram site, choosing the wanted element (our case: username field), right click on the field and click inspect. Next, on the outlined element (input field, in the inspect elementor) just right click, and copy Full Xpath.

You will have this:
/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div/div[1]/div/label/input

Next, replace line 66:
username = browser.find_element_by_name('username')
(which finds the field with the username in it)
with
username = browser.find_element_by_xpath('/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div/div[1]/div/label/input');
(which finds the field with the Xpath)

you will probably need to replace all the lines that were changed by instagram (password).

Remember, you could also find the wanted element by name but it's easier to right-click copy Xpath and paste it there.

Please come back with a feedback for this. Or write further any errors and I'll try to help you.

from instagrambot.

arda1984 avatar arda1984 commented on August 13, 2024 1

Thank you now I can log in, and I also figured out how I can let it close the notification and "save account information" popups. But I still don't know how this comment function works, I changed the explore link to my feed and also to the xpath of the comment line but it says that its unable to locate element

from instagrambot.

arda1984 avatar arda1984 commented on August 13, 2024

Thank you, I will try it later

from instagrambot.

arda1984 avatar arda1984 commented on August 13, 2024

code.txt
So this is the whole code.
I can log in, close the popups, and like the first post that comes to my feed, but I can't comment. In python, it says that the element is not interactable, it has to be something with the comment line, could you help me?

from instagrambot.

Radulepy avatar Radulepy commented on August 13, 2024

@arda1984
Sorry, I did not get all the notification.

I'm glad you figured it out.

For the comment section try taking the underlying elements from the comment section. Take the textarea element and not the div (since you should write text to it)

For example now, the comment textarea element has this xPath:
/html/body/div[6]/div[2]/div/article/div/div[2]/div/div/div[2]/section[3]/div/form/textarea

As you can see there are some arrays like this section[3]. These arrays can change with the post but I would suggest starting from that and going upwards. If the above xPath for comment element does not work try writing directly on the form by removing the textarea element from the xPath. Thus your element xPath will be this:

/html/body/div[6]/div[2]/div/article/div/div[2]/div/div/div[2]/section[3]/div/form

Waiting for your feedback!

from instagrambot.

arda1984 avatar arda1984 commented on August 13, 2024

Hey Radule, so yesterday I fixed the comment line, so now I can log in, close the popups, and like & comment (random comments is also working) on the first post that comes to my feed but how is it going to do the same thing on the next 8 posts and reload the feed page so there will be new posts shown?
codeupdated.txt
:)

from instagrambot.

arda1984 avatar arda1984 commented on August 13, 2024

@Radulepy

from instagrambot.

Radulepy avatar Radulepy commented on August 13, 2024

@arda1984
Hi, I'm glad you did it!

To refresh the page you just have to reload the feed page:
browser.get('https://www.instagram.com/explore/')
It was already doing it after iterating trough posts.

To comment and like the other post you have to iterate trough the elements with a for
In my code you can see starting from line 28 the 2 for's.

The most important line is 30:
post = browser.find_element_by_xpath('/html/body/div[1]/section/main/div/div[1]/div/div['+str(y)+']/div['+str(x)+']')

This line iterates the posts from 1 to 4 like this:
post = browser.find_element_by_xpath('/html/body/div[1]/section/main/div/div[1]/div/div[1]/div[1])
post = browser.find_element_by_xpath('/html/body/div[1]/section/main/div/div[1]/div/div[1]/div[2])
post = browser.find_element_by_xpath('/html/body/div[1]/section/main/div/div[1]/div/div[1]/div[3])
post = browser.find_element_by_xpath('/html/body/div[1]/section/main/div/div[1]/div/div[1]/div[4])
post = browser.find_element_by_xpath('/html/body/div[1]/section/main/div/div[1]/div/div[2]/div[1])
...

As you can see, the last div is increasing with x and the previous with y. These are the post xPath. You have to find the differences between the xPath of the IG posts and change accordingly.

Good luck!

from instagrambot.

arda1984 avatar arda1984 commented on August 13, 2024

@Radulepy
It almost works, it likes and comments on the first 2 posts on the feed page, but on the third one it just likes it and stops with the error;

File "C:/Users/ebrul/Desktop/InstagramBot-xy/instagramBotxy.py", line 87, in <module> start() File "C:/Users/ebrul/Desktop/InstagramBot-xy/instagramBotxy.py", line 80, in start likeAndComm() # likeAndComm function ---------------------------------------------------------------------------------------------------------------------------------------------------------- File "C:/Users/ebrul/Desktop/InstagramBot-xy/instagramBotxy.py", line 35, in likeAndComm postLike = browser.find_element_by_xpath('/html/body/div[1]/section/main/section/div/div[2]/div/article['+str(x)+']/div/div[3]/div/div/section[1]/span[1]/button').click() File "D:\Programme\JetBrains\PyCharm Community Edition 2021.2.1\env\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click self._execute(Command.CLICK_ELEMENT) File "D:\Programme\JetBrains\PyCharm Community Edition 2021.2.1\env\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute return self._parent.execute(command, params) File "D:\Programme\JetBrains\PyCharm Community Edition 2021.2.1\env\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response) File "D:\Programme\JetBrains\PyCharm Community Edition 2021.2.1\env\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <button class="wpO6b " type="button">...</button> is not clickable at point (69, 20). Other element would receive the click: <img alt="Instagram" class="s4Iyt" src="/static/images/web/mobile_nav_type_logo.png/735145cfe0a4.png" srcset="/static/images/web/mobile_nav_type_logo-2x.png/1b47f9d0e595.png 2x">

I did some research and tried to change some lines too but it didn't work

from instagrambot.

arda1984 avatar arda1984 commented on August 13, 2024

@Radulepy did you got the notification? :)

from instagrambot.

arda1984 avatar arda1984 commented on August 13, 2024

💀

from instagrambot.

Radulepy avatar Radulepy commented on August 13, 2024

@arda1984, so it can't find the element to click (input). Be sure to only add the input (textarea) element to the xPath.
Perhaps the 3rd element has a different xPath than the previous ones.

from instagrambot.

arda1984 avatar arda1984 commented on August 13, 2024

@Radulepy

/html/body/div[1]/section/main/section/div/div[2]/div/article[2]/div/div[3]/div/div/section[3]/div/form/textarea
/html/body/div[1]/section/main/section/div/div[2]/div/article[3]/div/div[3]/div/div/section[3]/div/form/textarea

The only difference between those is the article number where I put the x variable and it still doesn't work

from instagrambot.

arda1984 avatar arda1984 commented on August 13, 2024

@Radulepy Sorry but its been a week

from instagrambot.

Radulepy avatar Radulepy commented on August 13, 2024

@Radulepy

/html/body/div[1]/section/main/section/div/div[2]/div/article[2]/div/div[3]/div/div/section[3]/div/form/textarea
/html/body/div[1]/section/main/section/div/div[2]/div/article[3]/div/div[3]/div/div/section[3]/div/form/textarea

The only difference between those is the article number where I put the x variable and it still doesn't work

You should have something different depending on the post. Watch out you are pointing to the textarea not the post.

html/body/div[1]/section/main/section/div/div[2]/div/article[2]/div/div[3]/div/div/section[3]/div/form/textarea
html/body/div[1]/section/main/section/div/div[2]/div/article[2]/div/div[3]/div/div/section[2]/div/form/textarea
html/body/div[1]/section/main/section/div/div[2]/div/article[2]/div/div[3]/div/div/section[1]/div/form/textarea

something incrementing will point out that the post is changing.

from instagrambot.

Radulepy avatar Radulepy commented on August 13, 2024

@arda1984 Check the latest update

from instagrambot.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.