簡體   English   中英

使用Watir Webdriver Speed Issue進行鏈接提取

[英]Link Extraction using Watir Webdriver Speed Issue

我在運行Firefox的Linux系統上無頭使用Watir Webdriver,但在從網頁提取鏈接時遇到一些速度問題。 問題似乎出在使用多個幀時。 例如,可能需要10分鍾才能返回www.cnet.com上的所有鏈接。

為什么要花這么長時間,我有什么辦法可以加快速度?

例如,這些是我采取的一些典型時機。 從“默認框架”中獲取所有鏈接大約需要8秒鍾,但從框架中獲取所有鏈接則需要20秒:

No Frame: 8.304341236
Frame: 20.050233141
Frame: 20.070569295
....

實際上,在這種情況下,所有框架實際上都不包含任何鏈接。 (請參閱我提出的有關跳過某些框架的問題, Watir-Webdriver框架屬性與其他來源不兼容

從頁面提取鏈接的代碼如下:

b.links.each do |uri|
  # Check the HREF doesn't meet any of the following conditions. We don't want these so we ignore them.
  if uri.href != nil and uri.href != "" and uri.href[0,7].downcase != "mailto:" and uri.href[0,11].downcase != "javascript:"
    if debug
      puts " [x] [" + Process.pid.to_s + "] Discovered (noframe) URL: " + uri.href
    end
    # Add the discovered HREF to the array
    href.push(uri.href)
  end
end

用於從框架中提取鏈接的代碼如下:

b.frames.each do |frame|
  frame.links.each do |uri|
    if uri.href != nil and uri.href != "" and uri.href[0,7].downcase != "mailto:" and uri.href[0,11].downcase != "javascript:"
      if debug
        puts " [x] [" + Process.pid.to_s + "] Discovered Frame URL: " + uri.href
      end
      # Add the discovered HREF to the array
      href.push(uri.href)
    end
  end
end

任何幫助,將不勝感激。

我想我找到了問題的根源,但沒有找到問題的真正根本原因。

在我的代碼的前面,我為超時設置了以下值:

b.driver.manage.timeouts.implicit_wait = 20

如果我將其設置為3秒,那么我的代碼將運行得更快。

也就是說,為什么要等待超時值?

來自另一個站點的測試結果:

Timeout = 3
No Frame: 8.492559438
Frame: 3.037607356
Frame: 0.21291884
Frame: 0.187332136
Total: 27.3930574

Timeout = 20
No Frame: 8.698615854
Frame: 20.039797232
Frame: 0.202382168
Frame: 0.192850861
Total: 44.221886117

我想知道是否有錯誤。 如果找不到所需的元素,則似乎需要整個超時值才能返回。

請注意,我知道總數並不累加,因為我只是在測量某些代碼行之間的時間。 Total就是從頭到尾運行所需的時間,而其他時間在兩次循環之間。

暫無
暫無

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

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