2016-02-01 32 views
0

我試圖在我的域中加載一個頁面,然後分析頁面內容(獲取文本/圖像/等等及其位置)。我在2-3個不同的域上嘗試了我的代碼,它工作正常。僅在其中一個域中,當我加載我的頁面「subdomain.domain.com/page」時,selenium使用錯誤的基本url並以錯誤的方式加載所有相關路徑。例如,而不是加載下面的圖片:Selenium中的圖像/鏈接相對路徑錯誤

subdomain.domain.com/my_image.jpg 

它會嘗試加載此路徑,它顯然失敗:

subdomain.domain.com/page/my_image.jpg 

我第一次使用硒和PhantomJS,看到了問題。然後,我在Xvfb和Selenium上切換到Firefox,但我仍然看到同樣的問題。這裏是我如何加載頁面:

FirefoxBinary binary = new FirefoxBinary(new File("/usr/bin/firefox")); 
binary.setEnvironmentProperty("DISPLAY",System.getProperty("lmportal.xvfb.id",":10")); 
FirefoxProfile profile = new FirefoxProfile(); 
profile.setPreference("general.useragent.override", userAgent); 
driver = new FirefoxDriver(binary,null); 
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 
driver.get(url); 

有什麼想法?

回答

0

我發現問題在哪裏。我在網址的末尾加了一個'/'。顯然,它弄亂了這些相對路徑。因此,要解決這個問題,你可以加載:

subdomain.domain.com/page 

代替:

subdomain.domain.com/page/ 
+0

請不要忘記回來和接受,從而回答了這個問題將被標記爲紀念這個答案。謝謝! – JeffC

+0

當然。我必須等待2天.. – Nima