2

セレンを使用して、自分の Web ページを Googlebot として呼び出そうとしています。以下は私のコードですが、トラフィックをリダイレクトしてWebページを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ドライバー=新しいFirefoxDriver(プロファイル);

文字列サイト="http://store.nike.com/us/en_us/";

driver.get(site);

于 2011-05-24T16:57:28.097 に答える