无法旋转评论,Python 自动化,tkinter

Not Able To Spin Comments , Python automation ,tkinter

基本上我正在创建一个用于学习目的的机器人,我想做的是用户添加带有评论的逗号以旋转评论,但如果用户在评论框中添加嘿,“太棒了”“很酷”,然后机器人用“h”,“y”,“I,基本上是随机化第一个字符,

代码如下

def comment(driver, comment_custom,hashtags,count):

url = "https://www.instagram.com/explore/tags/"+ hashtags
driver.get(url)

wait = WebDriverWait(driver,10)
path = "/html/body/div[1]/section/main/article/div[1]/div/div/div[1]/div[1]/a/div/div[2]"
first_photo = wait.until(EC.presence_of_element_located((By.XPATH,path)))
first_photo.click()

time.sleep(1)

next_button1st = driver.find_element_by_xpath("/html/body/div[6]/div[1]/div/div/div/button")
next_button1st.click()   
time.sleep(1)


for i in range (int(count)):
    #comments on photo
    path = "/html/body/div[6]/div[2]/div/article/div/div[2]/div/div/div[2]/section[3]/div/form/textarea"
    comment = wait.until(EC.presence_of_element_located((By.CLASS_NAME,"Ypffh")))
    comment.click()
    time.sleep(1)
    commet_text = wait.until(EC.presence_of_element_located((By.CLASS_NAME, "Ypffh")))
    comment = comment_custom[randint(0, len(comment_custom)-1)]
    commet_text.send_keys(comment)
    
    #post comment button
    post_button = wait.until(
        EC.element_to_be_clickable((By.XPATH, "//button[contains(.,'Post')]")))
    post_button.click()
    time.sleep(1)

    next_button2st = wait.until(EC.presence_of_element_located((By.XPATH,"/html/body/div[6]/div[1]/div/div/div[2]/button")))
    next_button2st.click()

这是tkinter的代码

Comments_with_hash = Button(root, text="Comments_with_hashtags", height=1, width = 30,
command=lambda:comment(driver,comments.get(),hashtag.get(),likecount.get()))
Comments_with_hash.grid(padx=5,pady=5)

这是机器人的照片 https://prnt.sc/21k1nsr.png

我想要的期待评论

Nice and then Amazing and then amazing and nice basically in random 

已编辑 无法随机化睡眠时间 基本上我想做的是用户输入 2 个数字,如 1,5 来随机化每个操作之间的时间。 机器人图片:https://prnt.sc/21nj6xm 我正在使用的代码

time.sleep(randint(int(delay)))

错误

    time.sleep(randint(int((delay))))
    ValueError: invalid literal for int() with base 10: '1,5'

我不能 运行 但我猜:

comment_custom 是单个字符串,因此使用索引 comment_custom[index] 您可以从字符串中获取单个字符。

comment_custom = "hey,amazing,cool"

print( comment_custom[0] ) # char `h`

您必须将其转换为 strings/words 的列表,然后是列表

中的 select 个单词
comment_custom = "hey,amazing,cool"

words = comment_custom.split(',')

print( words[0] ) # string `hey`

您可以使用 random.choice(words) 而不是 words[random.randint(0, len(words)-1)]


所以你应该这样做

words = comment_custom.split(',')

comment = random.choice(words)

commet_text.send_keys(comment)