簡體   English   中英

使用Ruby捕獲Steam頁面的屏幕截圖

[英]Capture screenshot of Steam page with Ruby

我需要從Steam網頁捕獲屏幕截圖,其中包含交易報價錯誤,但是對於此操作,我必須獲得授權,並且我不知道將什么標頭發送到服務器。 我正在嘗試使用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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM