【发布时间】:2021-09-19 08:21:10
【问题描述】:
#this is the section where I think I need help
def random_comment():
with open('comments.txt', 'r') as f:
comments = [line.strip() for line in f]
comment = random.choice(comments)
return comment
#comment=============================
for url in urls:
print('Commenting to this post ---> ' + url)
comment = random_comment()
bot.get(url)
bot.implicitly_wait(1)
time.sleep(5)
bot.find_element_by_xpath('//*[@id="react-root"]/section/main/div/div/article/div[3]/section[1]/span[2]/button').click()
if doesnt_exist(bot, '//*[@id="react-root"]/section/main/section/div'):
print('Skipped - comments disabled')
else:
find_textarea = (
By.XPATH, '//*[@id="react-root"]/section/main/section/div/form/textarea')
WebDriverWait(bot, 50).until(
EC.presence_of_element_located(find_textarea)
)
comment_box = bot.find_element(*find_textarea)
WebDriverWait(bot, 50).until(
EC.element_to_be_clickable(find_textarea)
)
comment_box.click()
comment_box.send_keys(comment)
cmets 在一个 .txt 文件名 cmets.txt 中 出于此测试目的,cmets 是 1,2,....,10,每个数字都在其行上。 我希望评论机器人在不重复数字的情况下评论它们。 如果可能的话,甚至在被评论后删除号码。
【问题讨论】:
标签: python selenium selenium-webdriver bots