[英]How to export cookies/session from Mechanize to Selenium
I am using website that have no API so I decided to call actions from webside by Selenium.我正在使用没有 API 的网站,所以我决定通过 Selenium 从 web 端调用操作。 When I use selenium server, login will fail because of catcha so I decided to go login via Mechanize and then continue with Selenium since buttons or webside are generated by JS.
当我使用 selenium 服务器时,登录会因为 catcha 而失败,所以我决定通过 Mechanize 登录,然后继续使用 Selenium,因为按钮或 webside 是由 JS 生成的。 Is it possible to move active session generated by Mechanize and store it to Selenium so there wont be any login window anymore?
是否可以移动由 Mechanize 生成的活动会话并将其存储到 Selenium 以便不再有任何登录窗口?
Instead of python mechanize, try using ruby mechanize gem to get and store cookie values to file.尝试使用 ruby mechanize gem 来获取 cookie 值并将其存储到文件中,而不是 python mechanize。 Much easier to use.
使用起来要容易得多。 Use Chrome>developer tools>application to view cookies for logged in user.
使用 Chrome>开发者工具>应用程序查看登录用户的 cookie。 Determine minimum necessary cookies requirements by clicking on and deleting arbitrary cookies then refreshing to see if still logged in. Example:
通过单击并删除任意 cookie 然后刷新以查看是否仍处于登录状态来确定最低必需的 cookie 要求。示例:
require 'mechanize'
mechanize = Mechanize.new
page = mechanize.get(<somesite>)
page.forms[0].fields[0].value = <username>
page.forms[0].fields[1].value = <password>
page.forms[0].submit
mechanize.cookies[0].value
File.write("cookie.txt", mechanize.cookies[0].value)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.