Python Forum
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help me make a comment on youtube
#1
# imports
import random
import time
import csv
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

class Commenter:
# declares variables for commentor script
    def __init__(self):
        self.error = "[!] There was a critical error that broke the program!"
        self.browser = webdriver.Chrome(executable_path = '/Users/carsonrhodes/Desktop/Chrome Driver/chromedriver') 
        self.comment_box = " "
        self.comment = " "
    def fetch_input(self):
        print("- ")
        print("What video do you want to comment on?")
        print("- ")
        self.url = raw_input("Enter URL: ") #sample url : https://www.youtube.com/watch?v=uRVusUSNd2E
    def find_comment_box(self):
        try:
            print("Passing URL to Browser...")
            self.browser.get(self.url)
            bg = self.browser.find_element_by_css_selector('body')
            for _ in range(3):
                bg.send_keys(Keys.PAGE_DOWN)
                time.sleep(.5)
            for _ in range(3):
                bg.send_keys(Keys.PAGE_DOWN)
                time.sleep(.5)
            print("Fetching comment box...")

            self.comment_box = self.browser.find_element_by_xpath("//yt-formatted-string[contains(text(),'Add a public comment...')]")

        except Exception as exception:
            print(self.error)
            print("unable to find comment box:")
            print(exception)

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

# code starts here:
Commenter.login()
Commenter.fetch_input()
Commenter.find_comment_box()
The issue with this code is that the ID of the comment box keeps changing, which means the comment box is unidentifiable to the find_comment_box method.

Any suggestions?



Thanks in advance,
Carson.
Reply


Messages In This Thread
Help me make a comment on youtube - by caarsonr - Jun-20-2019, 10:15 PM
RE: Help me make a comment on youtube - by caarsonr - Jun-20-2019, 11:26 PM
RE: Help me make a comment on youtube - by caarsonr - Jun-21-2019, 01:10 AM
RE: Help me make a comment on youtube - by caarsonr - Jun-21-2019, 05:17 PM
RE: Help me make a comment on youtube - by caarsonr - Jun-21-2019, 07:49 PM
RE: Help me make a comment on youtube - by caarsonr - Jun-22-2019, 04:48 PM
RE: Help me make a comment on youtube - by caarsonr - Jun-22-2019, 11:52 PM
RE: Help me make a comment on youtube - by caarsonr - Jun-23-2019, 02:47 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  parsing comment tag ian 2 3,079 Jan-22-2018, 03:38 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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