2011-05-23 38 views
1

我想使用硒來調用我的網頁作爲googlebot。下面是我的代碼,但它確實重定向流量,以查看網頁爲googlebot ...有人可以幫助我指示我的請求以googlebot編程?useragent googlebot使用硒

package com.eviltester.captureNetworkTraffic; 
import org.junit.Test; 
import org.openqa.selenium.server.SeleniumServer; 

import com.thoughtworks.selenium.DefaultSelenium; 

public class SeleniumTrafficAnalyserExampleTest { 

@Test 
public void testProfileEvilTester() throws Exception{ 

    // Start the Selenium Server 
    SeleniumServer srvr = new SeleniumServer(); 
    srvr.start(); 

    // Create a Selenium Session with captureNetworkTraffic ready 
    String site = "...";//My URL 

    DefaultSelenium selenium = new DefaultSelenium("localhost", 4444, "*iexplore", site); 
    selenium.start("addCustomRequestHeader=true"); 
    selenium.addCustomRequestHeader("User-Agent", "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"); 

    // open a page to get the traffic 
    selenium.open("/us/en_us/"); 
    selenium.close(); 
    selenium.stop(); 
    srvr.stop(); 
} 

回答

0

下面代碼按預期方式工作

FirefoxProfile輪廓=新FirefoxProfile();
profile.setPreference(「general.useragent.override」,「Googlebot/2.1 + http://www.googlebot.com/bot.html)」);

WebDriver driver = new FirefoxDriver(profile);

String site =「http://store.nike.com/us/en_us/」;

driver.get(site);