-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPythonYoutube.py
More file actions
63 lines (45 loc) · 1.72 KB
/
PythonYoutube.py
File metadata and controls
63 lines (45 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as expect
from selenium.webdriver.common.keys import Keys
import time
from random import randint
class YoutubeCommentFounder():
def __init__(self,link):
self.link = link
def delay(self,n):
time.sleep(randint(2, n))
def CommentGetter(self):
options = webdriver.ChromeOptions()
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument("--headless")
driver = webdriver.Chrome()
driver.get(self.link)
wait_a_minute = WebDriverWait(driver, 600)
driver.maximize_window()
print("enter " + driver.title)
self.delay(5)
SCROLL_PAUSE_TIME = 2
CYCLES = 12
html = driver.find_element_by_tag_name('html')
html.send_keys(Keys.PAGE_DOWN)
html.send_keys(Keys.PAGE_DOWN)
time.sleep(SCROLL_PAUSE_TIME * 3)
for i in range(CYCLES):
html.send_keys(Keys.END)
time.sleep(SCROLL_PAUSE_TIME)
comment_elems = driver.find_elements_by_xpath('//*[@id="content-text"]')
all_comments = [elem.text for elem in comment_elems]
final = False
counter = 0
for i in all_comments:
b = str(i).lower()
if "rickroll" in b or "rolled" in b or "rikrolling" in b:
final = True
elif "rick" in b or "astley" in b:
counter+=1
if counter>10:
final = True
return final