V
V
Vitya Podpriklopolny2018-10-19 20:36:21
PHP
Vitya Podpriklopolny, 2018-10-19 20:36:21

Does the content change when the region changes?

Dobre I keep
parsing eldorado and ran into a problem
When I select a region, the displayed content changes here
When I save the site via cURL, for some reason the default city is Smolensk and I can't do anything about it. How do I change the region when saving?
Parsing so

<?php

require_once('vendor/autoload.php');
require_once('lib/phpQuery-onefile.php');
use DiDom\Document;

function get_content($url) {
  $ch = curl_init($url);
  curl_setopt($ch , CURLOPT_RETURNTRANSFER , true);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  // curl_setopt($ch , CURLOPT_HEADER , true);
  //curl_setopt ($ch , CURLOPT_USERAGENT , $_SERVER['HTTP_USER_AGENT']);
  $result = curl_exec($ch);
  $result = iconv('windows-1251', 'UTF-8', $result);
  return $result;
}
file_put_contents('data.txt', '');

function parser($url, $start, $end) {
  if($start < $end) {
    $file = get_content($url);
    $doc = phpQuery::newDocument($file);
    
    $posts = $doc->find('div.item');
    foreach($posts as $post) {
      $post = pq($post);
      $name = $post->find('.itemTitle a');
      $os = $post->find('div.description > p:contains("Операционная")');
      $price = $post->find('.discountPrice');
      $file = file_get_contents('data.txt');
      $file .= $name->text()."\n".$os->text()."\n".$price->text()."\n\n";
      file_put_contents('data.txt', $file);
      $next = $doc->find('.pages .pageActive')->next()->attr('href');
      if(!empty($next)) {
        $start ++;
        parser(('https://www.eldorado.ru'.$next), $start, $end);
      }
    }
  }
}

$start = 0;
$end = 4;
parser('https://www.eldorado.ru/cat/4005/', $start, $end);

?>

At the same time, tell me if I have the right way of thinking when saving spars content to a text file.
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question