示例#1
-8
 /**
  * @return Get user data from craglist
  */
 public function getInfo($link)
 {
     //Get the url name
     $url = Url::findOrfail($this->urlId);
     if ($url) {
         $ul = parse_url($url->name);
         $links = 'http://' . $ul['host'] . $link;
     }
     $crawler = $this->helper_crawler($links);
     $isBlock = $crawler->filter('p')->text();
     if (strpos($isBlock, 'blocked') != false) {
         //next process and change ip
         echo "Ip Address is blocked";
         die;
     } else {
         if ($crawler->filter('title')->count()) {
             $this->title = $crawler->filter('title')->text();
         }
         if ($crawler->filterXPath('//div[@class="mapAndAttrs"]')->count()) {
             $this->mapLocation = $crawler->filterXPath('//div[@class="mapAndAttrs"]')->html();
         }
         if ($crawler->filterXPath('//section[@id="postingbody"]')->count()) {
             $this->body = $crawler->filterXPath('//section[@id="postingbody"]')->html();
         }
         $lnk = $crawler->selectLink('reply')->link();
         //Ading user-agent
         $agent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.82 Safari/537.36';
         $client = new Client(['HTTP_USER_AGENT' => $agent]);
         $crawler = $client->click($lnk);
         if ($crawler->filterXpath("//div[@class='captcha']")->count()) {
             //Next process and change ip
             echo "Captcha given wait few hours";
         } else {
             $name = $email = $mobile = "";
             if ($crawler->filterXPath('//ul[not(@class)]/li[not(div)]')->count()) {
                 $name = $crawler->filterXPath('//ul[not(@class)]/li[not(div)]')->text();
             }
             if ($crawler->filterXPath('//ul/li/a[@class="mailapp"]')->count()) {
                 $email = $crawler->filterXPath('//ul/li/a[@class="mailapp"]')->text();
             }
             if ($crawler->filterXPath('//a[@class="mobile-only replytellink"]')->count()) {
                 $mb = $crawler->filterXPath('//a[@class="mobile-only replytellink"]')->attr('href');
                 $mobile = str_replace("tel:", '', $mb);
             }
             $url->leads()->create(['link' => $link, 'title' => $this->title, 'email' => $email, 'name' => $name, 'phone' => $mobile, 'mapLocation' => $this->mapLocation, 'body' => $this->body]);
         }
     }
     return redirect()->back()->with('message', "Please check scrap data");
 }