2

我正在尝试使用 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();
}
4

1 回答 1

0

下面的代码按预期工作

FirefoxProfile 配置文件 = 新的 FirefoxProfile();
profile.setPreference("general.useragent.override", "Googlebot/2.​​1+http://www.googlebot.com/bot.html)");

WebDriver driver = new FirefoxDriver(profile);

字符串站点 = "http://store.nike.com/us/en_us/";

driver.get(站点);

于 2011-05-24T16:57:28.097 回答