コード例 #1
0
ファイル: Page.php プロジェクト: izosa/page
 public function download($proxy = [])
 {
     $this->useragent = \Campo\UserAgent::random(['os_type' => 'Windows', 'device_type' => 'Desktop']);
     $this->handler = curl_init();
     curl_setopt($this->handler, CURLOPT_URL, $this->url);
     // proxy
     if (!empty($proxy)) {
         curl_setopt($this->handler, CURLOPT_HTTPPROXYTUNNEL, 0);
         curl_setopt($this->handler, CURLOPT_PROXY, $proxy['url']);
     }
     curl_setopt($this->handler, CURLOPT_USERAGENT, $this->useragent);
     curl_setopt($this->handler, CURLOPT_CUSTOMREQUEST, 'GET');
     curl_setopt($this->handler, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt($this->handler, CURLOPT_MAXREDIRS, 100);
     curl_setopt($this->handler, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($this->handler, CURLOPT_CONNECTTIMEOUT, 5);
     $this->html = curl_exec($this->handler);
     curl_close($this->handler);
 }
コード例 #2
0
 public function testFilterAcceptsArrays()
 {
     $userAgent = UserAgent::random(['os_type' => ['Xbox', 'NA', ''], 'agent_name' => ['Xbox One', 'NA', '']]);
     $this->assertContains('Xbox One', $userAgent);
 }
コード例 #3
0
 /**
  * @expectedException Exception
  */
 public function testException()
 {
     UserAgent::random(['os_type' => 'DOS', 'os_name' => 'MS-DOS 6.2', 'device_type' => 'unknown']);
 }