【问题标题】:useragent googlebot using selenium使用 selenium 的用户代理 googlebot
【发布时间】:2011-08-31 09:02:49
【问题描述】:

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

【问题讨论】:

    标签: selenium user-agent googlebot selenium-server


    【解决方案1】:

    以下代码按预期工作

    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(站点);

    【讨论】:

      猜你喜欢
      • 2011-12-25
      • 2018-03-01
      • 2011-06-12
      • 2020-02-23
      • 2015-02-14
      • 1970-01-01
      • 2020-10-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多