|
@@ -13,18 +13,17 @@ from selenium_stealth import stealth
|
|
import redis
|
|
import redis
|
|
import json
|
|
import json
|
|
import random
|
|
import random
|
|
|
|
+import fire
|
|
|
|
|
|
-profile_file = ['Profile 20', 'Profile 25']
|
|
|
|
|
|
|
|
-
|
|
|
|
-def open_driver():
|
|
|
|
|
|
+def open_driver(profile_file):
|
|
op = webdriver.ChromeOptions()
|
|
op = webdriver.ChromeOptions()
|
|
# op.binary_location = os.environ.get("GOOGLE_CHROME_BIN")
|
|
# op.binary_location = os.environ.get("GOOGLE_CHROME_BIN")
|
|
# op.add_argument('--headless')
|
|
# op.add_argument('--headless')
|
|
op.add_argument('--disable-dev-shm-usage')
|
|
op.add_argument('--disable-dev-shm-usage')
|
|
op.add_argument('--no-sandbox')
|
|
op.add_argument('--no-sandbox')
|
|
op.add_argument(r'user-data-dir=C:\Users\Administrator\AppData\Local\Google\Chrome\User Data')
|
|
op.add_argument(r'user-data-dir=C:\Users\Administrator\AppData\Local\Google\Chrome\User Data')
|
|
- op.add_argument('profile-directory=Profile 20')
|
|
|
|
|
|
+ op.add_argument(f"profile-directory={profile_file}")
|
|
op.add_experimental_option("excludeSwitches", ["enable-automation"])
|
|
op.add_experimental_option("excludeSwitches", ["enable-automation"])
|
|
op.add_experimental_option('useAutomationExtension', False)
|
|
op.add_experimental_option('useAutomationExtension', False)
|
|
driver = webdriver.Chrome(options=op,
|
|
driver = webdriver.Chrome(options=op,
|
|
@@ -44,7 +43,7 @@ def open_driver():
|
|
|
|
|
|
|
|
|
|
def comment_page(driver, url, comment):
|
|
def comment_page(driver, url, comment):
|
|
- if len(urls) == 0:
|
|
|
|
|
|
+ if len(url) == 0:
|
|
print('Youtube Comment Bot: Finished!')
|
|
print('Youtube Comment Bot: Finished!')
|
|
return []
|
|
return []
|
|
|
|
|
|
@@ -55,15 +54,15 @@ def comment_page(driver, url, comment):
|
|
driver.implicitly_wait(1)
|
|
driver.implicitly_wait(1)
|
|
|
|
|
|
if not check_exists_by_xpath(driver, '//*[@id="movie_player"]'):
|
|
if not check_exists_by_xpath(driver, '//*[@id="movie_player"]'):
|
|
- return comment_page(driver, urls, random_comment())
|
|
|
|
|
|
+ return comment_page(driver, url, random_comment())
|
|
time.sleep(4)
|
|
time.sleep(4)
|
|
driver.execute_script("window.scrollTo(0, 600);")
|
|
driver.execute_script("window.scrollTo(0, 600);")
|
|
|
|
|
|
if not check_exists_by_xpath(driver, '//*[@id="simple-box"]/ytd-comment-simplebox-renderer'):
|
|
if not check_exists_by_xpath(driver, '//*[@id="simple-box"]/ytd-comment-simplebox-renderer'):
|
|
- return comment_page(driver, urls, random_comment())
|
|
|
|
|
|
+ return comment_page(driver, url, random_comment())
|
|
|
|
|
|
if check_exists_by_xpath(driver, '//*[@id="contents"]/ytd-message-renderer'):
|
|
if check_exists_by_xpath(driver, '//*[@id="contents"]/ytd-message-renderer'):
|
|
- return comment_page(driver, urls, random_comment())
|
|
|
|
|
|
+ return comment_page(driver, url, random_comment())
|
|
|
|
|
|
WebDriverWait(driver, 20).until(
|
|
WebDriverWait(driver, 20).until(
|
|
EC.presence_of_element_located((By.CSS_SELECTOR, "ytd-comments ytd-comment-simplebox-renderer")))
|
|
EC.presence_of_element_located((By.CSS_SELECTOR, "ytd-comments ytd-comment-simplebox-renderer")))
|
|
@@ -106,16 +105,19 @@ def check_exists_by_xpath(driver, xpath):
|
|
return True
|
|
return True
|
|
|
|
|
|
|
|
|
|
-if __name__ == '__main__':
|
|
|
|
- r = redis.Redis(host='db.ptt.cx', port=6379, db=0, password='choozmo9')
|
|
|
|
- js = r.get('yt_video')
|
|
|
|
- jsobj = json.loads(js)
|
|
|
|
- videoId = random.choice(jsobj)
|
|
|
|
- url = f"https://www.youtube.com/watch?v={videoId}"
|
|
|
|
-
|
|
|
|
- # inp = open("url.txt", "r")
|
|
|
|
- # for line in inp.readlines():
|
|
|
|
- # urls.append(line)
|
|
|
|
|
|
+class JParams(object):
|
|
|
|
+
|
|
|
|
+ def get(self, profile):
|
|
|
|
+ print(profile)
|
|
|
|
+ r = redis.Redis(host='db.ptt.cx', port=6379, db=0, password='choozmo9')
|
|
|
|
+ js = r.get('yt_video')
|
|
|
|
+ jsobj = json.loads(js)
|
|
|
|
+ videoId = random.choice(jsobj)
|
|
|
|
+ url = f"https://www.youtube.com/watch?v={videoId}"
|
|
|
|
|
|
- driver = open_driver()
|
|
|
|
- comment_page(driver, url, random_comment())
|
|
|
|
|
|
+ driver = open_driver(profile)
|
|
|
|
+ comment_page(driver, url, random_comment())
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+if __name__ == '__main__':
|
|
|
|
+ fire.Fire(JParams)
|