[英]How can I generate a cookie file from Watir cookies
我正在尝试从 Watir 下载文件,但我不想使用loop sleep
方法。
我宁愿在交互的最后一刻,重新创建 Watir 在网页上的 session 并使用另一个库,例如 Typhoeus。
Typhoeus uses curl and can use cookies from a file, nonetheless, Watir generates a Hash Array, and if I ask to save it, it saves it as a YAML file.
有没有更快的转换方法?
StackOverflow 中的另一篇文章说 curl 使用Mozilla 风格的 cookie 文件。
因此,如果您的 Watir 实例是browser
并且您要写入的文件是file
,您可以执行
browser.cookies.to_a.each do |ch|
terms = []
terms << ch[:domain]
terms << ch[:same_site].nil? ? 'FALSE' : 'TRUE'
terms << ch[:path]
terms << ch[:secure] ? 'TRUE' : 'FALSE'
terms << ch[:expires].to_i.to_s
terms << ch[:name]
terms << ch[:value]
file.puts terms.join("\t")
end
然后你可以告诉 Typhoeus 使用file
的内容来继续使用相同的 cookies 导航。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.