使用selenium的useragent googlebot

时间:2011-05-23 18:35:30

标签: selenium user-agent googlebot selenium-server

我正在尝试使用selenium来调用我的网页作为googlebot。下面是我的代码,但它确实将流量重定向到以googlebot查看网页...有人可以帮助我以编程方式将我的请求定向到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();
}

1 个答案:

答案 0 :(得分:0)

下面的代码按预期工作

FirefoxProfile profile = new 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(网站);