简体   繁体   English

如何在Ruby Mechanize中使用从Javascript的document.cookie获得的cookie?

[英]How to use the cookie got from Javascript's document.cookie in Ruby mechanize?

I'm automate a login process using Ruby mechanize. 我使用Ruby机械化使登录过程自动化。 Because it's too complex to recreate the exactly process in mechanize, I choose to use existing cookies grabbed from browser document.cookie . 由于过于复杂以致无法在机械化中重新创建确切的过程,因此我选择使用从浏览器document.cookie抓取的现有cookie。 I want to know how can I use this string in Ruby mechanize. 我想知道如何在Ruby机械化中使用此字符串。 Thanks. 谢谢。

i dont think Mechanize runs Javascript, you'll have to use something like Selenium for that. 我不认为Mechanize运行Javascript,您必须使用Selenium之类的工具。

With Selenium, you can run arbitrary scripts. 使用Selenium,您可以运行任意脚本。 For example: 例如:

driver = Selenium::WebDriver.for :firefox
driver.get("http://some.url")
driver.execute_script("console.log('javascript')")
driver.close

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM