public function testGetUserAgent() { $uas = new UserAgentSwitcher('bot'); $googleBot = $uas->read('Googlebot/2.1'); $this->assertEquals("Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)", $googleBot); $uas->open('desktop'); $chromeLinux = $uas->read('Chrome 36 Lin'); $this->assertEquals("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36", $chromeLinux); }
function __construct() { $this->userAgent = new UserAgentSwitcher('desktop'); $this->setDefaultOption(CURLOPT_USERAGENT, $this->userAgent->getRandomRecord()); $this->cookie = new CurlCookie(); $this->shareInit(); $this->init(); }
public function getUserAgent() { return $this->currentUserAgent ?: $this->userAgent->getRandomRecord(); }