使用 Ruby 捕获 Steam 页面的屏幕截图
Capture screenshot of Steam page with Ruby
我需要从 Steam 网页截取屏幕截图,其中包含交易报价错误,但对于此操作我必须获得授权并且我不知道 header 发送到服务器的内容。
我正在尝试使用 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
您的错误发生的原因可能是您的代码在继续请求帐户页面之前没有等待登录成功,因此对帐户页面的请求没有设置正确的 cookie 并被重定向回到登录页面。您需要进行某种检查以确保登录已完成。像
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
我需要从 Steam 网页截取屏幕截图,其中包含交易报价错误,但对于此操作我必须获得授权并且我不知道 header 发送到服务器的内容。 我正在尝试使用 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
您的错误发生的原因可能是您的代码在继续请求帐户页面之前没有等待登录成功,因此对帐户页面的请求没有设置正确的 cookie 并被重定向回到登录页面。您需要进行某种检查以确保登录已完成。像
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