Python Forum
Syntax Error : I can't identify what's wrong!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Syntax Error : I can't identify what's wrong!
#1
# imports
import random
import time
from selenium import webdriver

class Commenter:
# declares variables for commentor script
    def __init__(self):
        self.error = "[!] There was an error!"
        self.url =  " "
        self.browser = webdriver.Chrome(executable_path = '/Users/carsonrhodes/Desktop/Chrome Driver/chromedriver')
        self.comment_box = " "

# logs user into browser so that they may comment on a video.
    def login(self):

        # URL for google login
        url = "https://accounts.google.com/servicelogin"

        try:
            browser.get(url)

            print("What is your Google email?")
            email = input("")
            print("What is your Google password?")
            password = input("")

            email_input = browser.find_element_by_type("email")
            email_input.send_keys(email, Keys.ENTER)
            password_input = browser.find_element_by_type("password")
            password_input.send_keys(password, Keys.ENTER)

        except:
            print(" ")
            print(self.error)

# fetches input URL from user
    def fetch_input(self):
        print("- ")
        print("What video do you want to comment on?")
        print("- ")
        self.url = input("Enter URL: ") #sample url : https://www.youtube.com/watch?v=SEpmYLu-CCA

# finds comment box so that the script can comment.
    def find_comment_box(self):
        try:
            self.browser.get(self.url)
            self.comment_box = self.browser.find_element_by_id(contenteditable-root)
        except:
            print(self.error)

# generates a comment from CSV file.
    def generate_comment(self):
         comments = []
         try:
            with open('Comments for Bot .csv') as csv_file:
                csv_reader = csv.reader(csv_file, delimiter='\n')
                for row in csv_reader:
                 comments.append(row)

            return(random.choice(comments))
         except:
            print(" ")
            print(self.error)

# fetches comment from generating script
    def fetch_comment(self):
        comment = self.generate_comment()
        print("[!] Comment generated successfully!")
        return(comment)

# enters comment into comment box on YouTube
    def enter_comment(self):
        self.comment_box.send_keys(self.fetch_comment())


Commenter = Commenter() #creates class (cannot call methods without calling class)

# code starts here:
Commenter.login()
Commenter.fetch_input()
Commenter.find_comment_box()
Commenter.generate_comment()
What seems to be wrong here? I can't figure it out.
Reply


Messages In This Thread
Syntax Error : I can't identify what's wrong! - by caarsonr - May-31-2019, 04:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Syntax error for "root = Tk()" dlwaddel 15 1,206 Jan-29-2024, 12:07 AM
Last Post: dlwaddel
Photo SYNTAX ERROR Yannko 3 396 Jan-19-2024, 01:20 PM
Last Post: rob101
  identify not white pixels in bmp flash77 17 2,503 Nov-10-2023, 09:21 PM
Last Post: flash77
  error "cannot identify image file" part way through running hatflyer 0 681 Nov-02-2023, 11:45 PM
Last Post: hatflyer
  Receiving this error in my "response" and causes script to return wrong status cubangt 18 2,083 Aug-13-2023, 12:16 AM
Last Post: cubangt
  Wrong type error rowan_bradley 6 1,228 Aug-07-2023, 10:44 AM
Last Post: rowan_bradley
  Syntax error while executing the Python code in Linux DivAsh 8 1,613 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Code is returning the incorrect values. syntax error 007sonic 6 1,240 Jun-19-2023, 03:35 AM
Last Post: 007sonic
  Compiles Python code with no error but giving out no output - what's wrong with it? pythonflea 6 1,575 Mar-27-2023, 07:38 AM
Last Post: buran
  syntax error question - string mgallotti 5 1,325 Feb-03-2023, 05:10 PM
Last Post: mgallotti

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020