I’m learning python and I’m not finding out why the script doesn’t work, this is a tutorial on youtube someone can help me

Asked

Viewed 107 times

-3

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
import random

class InstagramBot:
    def __init__(self, username, password):
        self.username = username
        self.password = password
        self.driver = webdriver.Firefox(r"C:\Users\paulo\Desktop\geckdriver.exe")
        
    def login(self)
    driver = self.driver
    driver.get("https://www.instagram.com.br")  

jhonatanBot = InstagramBot('vaca','doido')
jhonatanBot.login()
  • Sorry I didn’t get a good look

  • What is the error message?

  • File "c: Users paulo Desktop Igbot igBot.py", line 12 def login(self) Syntaxerror: invalid syntax

  • You missed two stitches : after the declaration. It should look like this def login(self):

  • Increase the recoil of statements driver = self.driver and driver.get("https://www.instagram.com.br") . Python is indentation sensitive.

  • thank you I will test our do not know how I forgot the two points kkkkkk

  • It worked out thanks

Show 2 more comments

1 answer

2

Some changes must be made to your code for it to work, come on!

login(self)
driver = self.driver
driver.get("https://www.instagram.com.br")

First point to note is that in the "login" function after closing parentheses you should add ":" (two points), otherwise we will have a syntax error. Then I’d stay that way:

login(self):

Another point to note is code indentation in the login function. Python requires a standardized indentation. The misuse, will result in non-execution, or else in the general malfunction of the program. Correcting would be like this

login(self):
    driver = self.driver
    driver.get("https://www.instagram.com.br")

I’ll leave you a hint, too. In the login function you would not need to assign the "self.driver" to a variable called "driver" because, just above in the constructor def __init __ you have already created it. The reserved word self serves for you to refer to the object itself(instance) and just leave the code in this way:

login(self):
    self.driver.get("https://www.instagram.com.br")

And this way you can even reuse "better" your driver in all parts of the program.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.