Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require __DIR__ . '/vendor/autoload.php';
- class CrawlerSupport{
- private $use_proxy;
- function __construct($use_proxy = false){
- $this->use_proxy = $use_proxy;
- }
- function loadUrl($url){
- if($html = $this->curl($url)){
- return new Rct567\DomQuery\DomQuery($html);
- }
- return false;
- }
- private function curl($url, $try = 1){
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- if($this->use_proxy){
- //TODO::Set curl to use proxy
- }
- $response_content = curl_exec($ch);
- $response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- if($response_code !== 200 && $try <= 4){
- return $this->curl($url, $try++);
- }elseif($response_code !== 200){
- return false;
- }
- curl_close($ch);
- return $response_content;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement