1

So I'm trying to build a bot with python and selenium this is my code

from selenium import webdriver
import os
import time

class InstagramBot:

    def __init__(self, username, password):
        self.username = username
        self.password = password
        self.driver = webdriver.Chrome(executable_path='./chromedriver.exe')
        self.driver.get('https://www.Instagram.com/')

The problem is nothing will happen when I try the python bot.py I've tried py bot.py too it didin't throw any errors but the commands really do nothing

please can someone help me findout what the problem is???

I've tried driver = webdriver.chrome ... outside the class and it works but when i put it in the InstagramBot class it wont work

im using python3.6.5 and ive tried other python versions too it didint help

2
  • Is this the entire code? Have you remembered to initialise your class to call the function? e.g. i = InstagramBot(). Might be better to add another method to run your bot def run(self): ... then you can call InstagramBot().run() Commented Nov 25, 2021 at 12:54
  • yes sir its not complete but it will be when i find out whats the problrm Commented Nov 25, 2021 at 13:22

1 Answer 1

1

You were close enough. As you have defined the Class, now you simply need to create an instance so the constructor gets executed calling it from the main as follows:

from selenium import webdriver
import os
import time

class InstagramBot:

    def __init__(self, username, password):
    self.username = username
    self.password = password
    self.driver = webdriver.Chrome(executable_path='./chromedriver.exe')
    self.driver.get('https://www.Instagram.com/')

InstagramBot("naa-G", "naa-G")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.