如何将我的 document.txt 中的特定行添加到具有特定 ID 的 YouTube 评论字段,然后移至我的 document.txt 中的下一行。 YouTube 评论字段的 ID 是“contenteditable-root”。我已经创建了这段代码,但是添加到 YouTube 评论字段中的文本显示在方括号中,例如 ["Hello"]
或者在第二个例子中它什么都不显示
示例 1:
file = 'comments.txt'
File.readlines(file).each do |i|
files = [i]
files.each { |val|
browser.execute_script("document.getElementById('contenteditable-root').innerHTML = '#{files}';")
}
end
示例 2:
line_number = 1
loop do
comments = IO.readlines('comments.txt')[line_number-1]
browser.execute_script("document.getElementById('contenteditable-root').innerHTML = '#{comments}';")
line_number += 1
end
comment.txt 文件:
Hellooo !!
hi
Goodbye
Goodnight
最佳答案
假设这里的一大堆其他事情都是正确的,你正在做一个非常奇怪的迭代,你应该只使用:
file = 'comments.txt'
File.readlines(file).each do |i|
browser.execute_script("document.getElementById('contenteditable-root').innerHTML = '#{i}';")
end
关于ruby-on-rails - 将 document.txt 中的特定行添加到具有特定 id 的注释字段,然后移至下一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57575901/