# 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.
Syntax Error : I can't identify what's wrong!
|
Syntax Error : I can't identify what's wrong!
|
|
May-31-2019, 04:18 PM
Please, post the entire traceback that you get.
Take a time to read What to include in a post You should get also IndentationError (e.g. look at lines 54-64)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link Create MCV example Debug small programs (May-31-2019, 04:18 PM)buran Wrote: Please, post the entire traceback that you get. Yes, my apologies regarding the tags, Right off the bat, I get an error from the login method (the except block is ran) When I insert the link, I get a syntax error. Here is the console when the program is ran:
Which python version are you using?
May-31-2019, 04:45 PM
this looks strange:
for start remove the try/except block from the login() method to fix this error. when using all-catch exception you mask what is going onalso don't use Commenter as instance variable, use commenter
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link Create MCV example Debug small programs
May-31-2019, 04:46 PM
ah, Yoriz has a point
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link Create MCV example Debug small programs
Jun-10-2019, 01:25 AM
Quote:self.url = input("Enter URL: ")python2.x is raw_input()Either use python3.x or change all input() to raw_input()
Recommended Tutorials:
(Jun-10-2019, 01:36 AM)metulburr Wrote:Quote:self.url = input("Enter URL: ")python2.x is Hey I changed all my inputs to raw_inputs, thank you for this tip. I still have my except blocks going off and I'm not quite sure why. My login method doesn't seem to work at all.
Jun-10-2019, 05:29 AM
Change your try/except blocks, so the exception that happens is actually displayed
try:
...
...
except Exception as exception:
print(exception)
|
|
|
Users browsing this thread: 1 Guest(s)
