A
A
Andrew Flosin2020-02-02 19:33:59
PHP
Andrew Flosin, 2020-02-02 19:33:59

How to solve the problem with parsing in php script?

Good day, I've been suffering for a week now, the script works only through a proxy.
And the proxies stop working every 5 minutes in the script itself, for what reason is not known.
I'm sorry to help.

lic function Grab(){
            $proxy_host = ''; // Прокси в формате ip:port
            $proxy_auth = ''; // Логин с паролем в формате login:parol
            
      $agent = 'Mozilla/5.0 (Linux; Android 4.0.4; HUAWEI U9508 Build/HuaweiU9508) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19'; 
            $ch = curl_init($this->url);
      curl_setopt($ch, CURLOPT_USERAGENT, $agent);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_REFERER, 'https://google.com/');
            curl_setopt($ch, CURLOPT_PROXY, $proxy_host);
            curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxy_auth);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

            $this->page = curl_exec($ch);
            $error = curl_error($ch);
            curl_close($ch);

            if ($error)
                die("Failed to grab olx page: " . $error);

            if (!$this->page)
                die("Failed to grab olx page.");
      
      $this->data["item"]["script_order"] = $this->FastCut($this->page, '<script type="text/javascript" src="https://static-olxeu.akamaized.net/static/olxua/packed/', "</script>");
      $this->data["item"]["script"] = $this->FastCut($this->page, '<!-- TRACKING CONTRIB -->', "<!-- TRACKING CONTRIB -->");
      $this->data["item"]["header"] = $this->FastCut($this->page, "<head>", "</head>");
            $this->data["page_title"] = $this->FastCut($this->page, "<title>", "</title>");
      $this->data["item"]["vetka"] = $this->FastCut($this->page, '<div class="rel breadcrumbbox">', '</div>');
      $this->data["item"]["price"] = $this->FastCut($this->page, '<strong class="xxxx-large not-arranged">', '</strong>');
      $this->data["item"]["price2"] = $this->FastCut($this->page, '<strong class="xxxx-large margintop7 block not-arranged">', '</strong>');
      $this->data["item"]["price3"] = $this->FastCut($this->page, '<strong class="xxxx-large not-arranged">', '</strong>');
      $this->data["item"]["map"] = $this->FastCut($this->page, '<div class="offer-user__location">', '</div>');
      $this->data["item"]["city"] = $this->FastCut($this->page, '<span class="block normal brkword">', '</span>');
      $this->data["item"]["dateshop"] = $this->FastCut($this->page, '<span class="block normal margintop5">', '</span>');
      $this->data["item"]["nameshop"] = $this->FastCut($this->page, '<span class="block brkword xx-large">', '</span>');
      $this->data["item"]["bigtitle"] = $this->FastCut($this->page, '<div class="pding5 clr">', '</div>');
      $this->data["item"]["more"] = $this->FastCut($this->page, '<span class="block">', '</span>');
      $this->data["item"]["user"] = $this->FastCut($this->page, '<div class="offer-user__details ">', '</div>');
      $this->data["item"]["or"] = $this->FastCut($this->page, '<div class="flagged-offers">', '</div>');
      $this->data["item"]["titlebox"] = $this->FastCut($this->page, '<h1>', '</h1>');
      $this->data["item"]["titlebox_detalis"] = $this->FastCut($this->page, '<div class="offer-titlebox__details">', '</div>');
      $this->data["item"]["title_offer"] = $this->FastCut($this->page, '<div class="offer-titlebox__buttons">', '</div>');
      $this->data["item"]["title_info"] = $this->FastCut($this->page, '<div class="clr lheight20 large" id="textContent">', '</div>');
      $this->data["item"]["img"] = $this->FastCut($this->page, '<div class="tcenter img-item">', '</div>');
      $this->data["item"]["views"] = $this->FastCut($this->page, '<div class="pdingtop10">', '</div>');
      $this->data["item"]["photo"] = $this->FastCut($this->page, '<div class="photosbar">', '</div>');
      $this->data["item"]["photo_opener"] = $this->FastCut($this->page, '<div id="photo-gallery-opener" class="photo-handler rel inlblk">', '</div>');


            return $this->data;
        }

        private function ToLinesArray($data){
            return explode("\n", $data);
        }

        private function FastCut($data, $from, $to){
            return explode($to, explode($from, $data)[1])[0];
        }
    }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrew Flosin, 2020-02-03
@Flexxi

Don't have a solution?

D
Dr10s, 2020-02-04
@Dr10s

How do you know they stop working? Can you just ban the server you are accessing?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question