2015-02-09 28 views
0

「從服務器接收重複標頭」下面是一些額外的信息來回答問題的意見:鉻返回

  1. 這是一個私人網站需要用戶名和密碼。不幸的是,出於安全原因,我無法提供這些信息。
  2. 你看到的是300行腳本的一部分。它執行以下操作:轉到URL,登錄到頁面,瀏覽到特定頁面,從下拉列表中讀取文件列表,更改每個帳戶的下拉選項並下載文件。繼續下去,直到下載所有文件。
  3. 該網站有大量的文件。目前該腳本可以下載30多個文件。它在每次運行時都在同一個文件上失敗。
  4. 如果您有任何問題,請讓我知道。

我有一個腳本從網站下載多個文件。

我收到以下錯誤在Chrome中:從服務器

我在網上搜索,它似乎是指定的文件名需要加引號收到

重複標頭。不幸的是,我在下載文件時沒有指定文件名,所以我不知道如何解決這個問題。

下面是代碼的一些部分我使用:

#!/bin/ruby 

require 'rubygems' 
require 'watir-webdriver' 
require 'selenium-webdriver' 
require 'headless' 

headless = Headless.new(autopick: true, reuse: false, destroy_at_exit: true).start 

prefs = { 
    :download => { 
    :prompt_for_download => false, 
    :default_directory => path['xdrive'] 
    }, 
    :profile => { 
    :content_settings => { 
          :pattern_pairs => { 
               :* => { 
                 :'multiple-automatic-downloads' => 1 
                 } 
          } 
         } 
    } 
} 
client = Selenium::WebDriver::Remote::Http::Default.new 
client.timeout = 60 # seconds - default is 60 
d = Selenium::WebDriver.for :chrome, :prefs => prefs, :http_client => client, :switches => %w[--disable-popup-blocking --disable-translate] 
b = Watir::Browser.new d 

@myLinks.each { |option| 
    puts "Getting " + option[:text] 
    b.select_list(:id, "someField").select_value(option[:value]) 
    sleep 6 

    b.goto "https://www.somewebsite.com/DownloadFile.ashx" 
    sleep 1 
} 
+0

感謝您編輯我的問題。 – Andrey 2015-02-09 16:46:15

+0

你可以使用http客戶端而不是webdriver嗎?例如 需要「httparty」 File.open(「/ tmp/filename.ext」,「wb」)do | f | f.write HTTParty.get(「https://www.somewebsite.com/DownloadFile.ashx」).parsed_response end – jmccure 2015-02-09 19:46:22

+0

該腳本包含300多行代碼,包含身份驗證和其他操作。我只提供了下載腳本的部分內容。 – Andrey 2015-02-09 19:48:35

回答

0

看評論基於由@Justin柯問了問原來的問題

,海報上發現有帳戶名包含導致錯誤的逗號的數據。從他的夾具數據中刪除逗號解決了他的問題。

相關問題