Every time I enter the command "python3 bot.py" I get this error.
I've already tried adding to the path, but I'm 99% sure that's not to issue as I selected the add to path option whilst installing python.
Error:
The term 'python3' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a
path was included, verify that the path is correct and try again.
At line:1 char:8
+ python3 <<<< bot.py
+ CategoryInfo : ObjectNotFound: (python3:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Or when entering "python bot.py"
File "bot.py", line 25
def nav_user(self.user):
^
SyntaxError: invalid syntax
I've just tried "python bot.py" and I've gotten more errors
File "bot.py", line 35
if __name__ == '__main__':
^
SyntaxError: invalid syntax
Heres all the code:
from selenium import webdriver
import os
import time
import configparser
class InstagramBot:
def __init__(self, username, password):
self.username = username
self.password = password
self.base_url = 'https://www.instagram.com'
self.driver = webdriver.Chrome('./chromedriver.exe')
self.login()
def login(self):
self.driver.get('{}/accounts/login/'.format(self.base_url))
self.driver.find_element_by_name('username').sendkeys(self.username)
self.driver.find_element_by_name('password').sendkeys(self.password)
self.driver.find_element_by_xpath("//div[contains(text(), 'Log In')]")[0].click()
def nav_user(self,user):
self.driver.get('{}/{}/'.format(self.base_url, user))
def follow_user(self, user):
self.nav_user(user
if __name__ == '__main__':
config = './config.ipni'
cparser = configparser.ConfigParser()
cparser.read(config_path)
username = cparser['AUTH']['USERNAM'E]
password = cparser['AUTH']['PASSWORD']
ig_bot = InstagramBot(username, password)
ig_bot.nav_user('test')
ig_bot.follow_user('test')
The first error is because python3
is either not installed or its folder hasn't been added to your Path environment variable. Use python
instead.
The second is a syntax error, looks like it should be:
def nav_user(self,user):
note the comma ,
Regarding the other code snippet, there are multiple syntax errors. Consider using flake8 or pylint to check your code before running it. It will save you time. Stackoverflow is not a syntax checking service.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.