打开页面时保留 cookie
我正在尝试创建一个脚本,该脚本将登录到 drupal,然后能够访问网站上的每个页面。
我遇到的问题是在对网站进行身份验证时...它似乎无法保留 cookie 并为每个请求使用它们,所以我未经授权的 drupal 事情。
http = Net::HTTP.new('www.example.com', 443)
http.use_ssl = true 路径 = '?q=front_page&destination=front_page'
resp, data = http.get(path, nil) cookie = resp.response['set-cookie']
data = '"name=jobbloggs&pass=securepassword&op=登录&form_id=user_login'
headers = { 'Cookie' =>;饼干,
'推荐人' => 'https://www.example.com/',
'内容类型' => 'application/x-www-form-urlencoded' }
resp, data = http.post(路径、数据、标题)
放置数据
任何帮助将不胜感激。
I'm trying to create a script of which will log into drupal, and then is able to access every page on the site.
The issue i'm having is when authenticating to the site... it doesn't seem to be able to retain cookies and use them for each request, so then drupal things I'm unauthorised.
http = Net::HTTP.new('www.example.com', 443)
http.use_ssl = true path = '?q=front_page&destination=front_page'
resp, data = http.get(path, nil) cookie = resp.response['set-cookie']
data = '"name=jobbloggs&pass=securepassword&op=Log in&form_id=user_login'
headers = { 'Cookie' => cookie,
'Referer' => 'https://www.example.com/',
'Content-Type' => 'application/x-www-form-urlencoded' }
resp, data = http.post(path, data, headers)
puts data
Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能会发现使用 mechanize 更容易,它会为您管理 cookie,并且有更方便的 DSL 用于屏幕抓取和类似目的。
You might find it easier to use mechanize, which will manage cookies for you and has a more facile DSL for screen scraping and similar purposes.