简体   繁体   English

如何将 cookie/session 从 Mechanize 导出到 Selenium

[英]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.

相关问题 从selenium加载饼干与cookielib机械化 - loading cookies from selenium to mechanize with cookielib python-requests cookie将会话导出到硒 - python-requests cookies export session to selenium 如何从机械化获取Cookie以在pdfkit中使用 - How to get cookies from mechanize to use in pdfkit 将 cookie 从请求会话传输到硒会话 - Transfering cookies from a Request session to a selenium session 如何手动将更多cookie添加到已在机械化中设置cookie的会话中? - How do I manually add more cookies to a session which already has cookies set in mechanize? 如何使用python模块“mechanize”使用chrome扩展名“cookies.txt export”导出的cookies.txt登录网站? - How to login a website using python module “mechanize” with a cookies.txt exported by the chrome extension “cookies.txt export”? 如何将会话和 cookie 从 Selenium 浏览器加载到 Python 中的请求库? - How do I load session and cookies from Selenium browser to requests library in Python? 如何将 session 和 cookies 从请求库加载到 ZA7F5F35426B5674117Z23 中的 Selenium 浏览器? - How do I load session and cookies from requests library to Selenium browser in Python? Python:迭代从请求会话到Selenium的传输cookie - Python: iterate transfer cookies from requests session to Selenium 如何使用mechanize cookies获取http页面? - How to get a http page using mechanize cookies?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM