简体   繁体   English

使用Ruby捕获Steam页面的屏幕截图

[英]Capture screenshot of Steam page with Ruby

I need to capture screenshot from steam web page, that contains trade offer error, but for this action i have to be authorized and I don't know what header send to server. 我需要从Steam网页捕获屏幕截图,其中包含交易报价错误,但是对于此操作,我必须获得授权,并且我不知道将什么标头发送到服务器。 I am trying to do this with webshot gem , filling my credentials with capybara, but this not working and it captures login page 我正在尝试使用webshot gem来执行此操作,并用水豚填充凭据,但这无法正常工作,并且它捕获了登录页面

 ws.start_session do
  visit 'https://store.steampowered.com/login/'
  within(:css, 'form[name="logon"]') do
    fill_in 'username', {:id => 'input_username', :with => 'test'}
    fill_in 'password', {:id => 'input_password', :with => 'password'}
  end
  click_button('Sign in', exact: true)
end.capture 'https://store.steampowered.com/account', 'example.png', width: 500, height: 500, quality: 85

Your error is probably occurring because your code doesn't wait for the login to be successful before moving on to request the account page, so the request for the account page doesn't have the correct cookies set and gets redirected back to the login page. 您的错误可能是由于您的代码在继续请求帐户页面之前没有等待登录成功而导致的,因此对帐户页面的请求未设置正确的Cookie,而是被重定向回登录页面。 You need to do some sort of check to make sure the login has completed. 您需要进行某种检查以确保登录已完成。 Something like 就像是

ws.start_session do
  visit 'https://store.steampowered.com/login/'
  within(:css, 'form[name="logon"]') do
    fill_in 'input_username', with: 'test'
    fill_in 'input_password', with: 'password'
  end
  click_button('Sign in', exact: true)
  page.assert_text('You are now logged in!') # whatever text shows on the page after successfully logging in
end.capture 'https://store.steampowered.com/account', 'example.png', width: 500, height: 500, quality: 85

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

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