I'm currently improving my first script written in Python, and started implementing loops in it.
# configuring channel list
channel = ["https://www.youtube.com/signin?next=%2F&feature=channel_switcher&skip_identity_prompt=False&action_handle_signin=true&pageid=113904157503595102905&authuser=0",
"https://www.youtube.com/signin?next=%2F&feature=channel_switcher&skip_identity_prompt=False&action_handle_signin=true&pageid=101186525882577868135&authuser=0",
"https://www.youtube.com/signin?next=%2F&feature=channel_switcher&skip_identity_prompt=False&action_handle_signin=true&pageid=106482002867547448545&authuser=0",
"https://www.youtube.com/signin?next=%2F&feature=channel_switcher&skip_identity_prompt=False&action_handle_signin=true&pageid=114381370173908842364&authuser=0",
"https://www.youtube.com/signin?next=%2F&feature=channel_switcher&skip_identity_prompt=False&action_handle_signin=true&pageid=108356515128895175238&authuser=0",
]
comments = ["comment1","comment2","comment3","comment4","comment5","comment6"]
videos = ["https://youtube.com/video1",
"https://youtube.com/video2",
"https://youtube.com/video3",
"https://youtube.com/video4",
"https://youtube.com/video5",
"https://youtube.com/video6"]
# channel loop
i = 0
x = 0
while x<len(videos):
driver.get(channel[i])
print("Switched account")
# heading to youtube vid
driver.implicitly_wait(10)
driver.get(video[x])
print("Browsed to the video")
time.sleep(1)
# scrolling to show comment field
driver.execute_script("window.scrollTo(0, 500);")
#clicking the comment field
driver.find_element_by_id("placeholder-area").click()
# entering comment
print("Typing comment")
comment = driver.find_element_by_id("contenteditable-textarea")
comment.send_keys(random.choice(comments))
print("Comment entered in field")
# submitting comment
print("Waiting for button")
time.sleep(1)
driver.find_element_by_xpath('//*[@id="submit-button"]').click()
print("Comment submitted")
i = i + 1
if i == 6:
x = x + 1
i = 0
What the script is supposed to do is : switch the current YouTube channel, browse to a defined video, post a random comment to a vid, and just loop through the channels until all of them have been done. Then, everything repeats with a different video.
Problem in there is that I previously had a set of comments for each channel.
I'm currently wondering how I could use random.choice
with a different list of comments every loop.
As a list can't have multiple values at a same index, I don't really see how I can achieve this.
I also thought about changing the list values during the loop but not really sure it's the best way to do this.
Would it be possible to change the list values in the loop, leave the loop to reset the list values, and just launch the loop again to kind of "restart the process" ?
If it's too vague, please do not hesitate to tell me where it needs more information. Thanks in advance for your help.
Aucun commentaire:
Enregistrer un commentaire