Например парсинг
bing.index

Реализация на языке php

PHP (англ. PHP: Hypertext Preprocessor — «PHP: препроцессор гипертекста»; первоначально Personal Home Page Tools[4] — «Инструменты для создания персональных веб-страниц»; произносится пи-эйч-пи) — скриптовый язык[5] программирования общего назначения, интенсивно применяемый для разработки веб-приложений. В настоящее время поддерживается подавляющим большинством хостинг-провайдеров и является одним из лидеров среди языков программирования, применяющихся для созданиядинамических веб-сайтов[6].

Постановка задания
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php

    function __dopost($url,$data) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $output = curl_exec($ch);
        $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        return array('code'=>$code, 'content'=>$output);
    }

    $apikey = "[API КЛЮЧ]"; // его можно посмотреть на странице http://smartfetch.io/private/profile/
    // Задание - это список ассоциативных массивов Ключ-Значение
    $data = array('task'=>'bingindex',
                  'data'=>json_encode(array('param'=>array(),
                                            'data'=>array(
                                                array(  ),
                                                array(  ),
                                                array(  )
                                             ))));

    $resp = __dopost("http://smartfetch.io/".$apikey."/api2/", $data);
    $response = json_decode($resp['content']);

    if ($response->success) {
        print 'ok '.$response->hash.PHP_EOL;
    }  else {
        if (property_exists($response, 'message')) {
            print 'error '.$response->message.PHP_EOL;
        }  else {
            print 'error '.PHP_EOL;
        }
    }
?>
Получение задания
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php

    function __doget($url) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
        $output = curl_exec($ch);
        $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
         return array('code'=>$code, 'content'=>$output);
    }

    $apikey = "[API КЛЮЧ]"; // его можно посмотреть на странице http://smartfetch.io/private/profile/
    $hash = ИДЕНТИФИКАТОР ЗАДАНИЯ;

    $resp = __doget("http://smartfetch.io/".$apikey."/get/".$hash);

    if ($resp['code']==200) {
        //Создаем временный файл
        $tmp = tmpfile();
        //Записываем в него содержимое zip-архива
        fwrite($tmp, $resp['content']);
        //Получаем путь ко временному файлу
        $si = stream_get_meta_data($tmp);
        $tmpfilename = $si['uri'];
        //И открываем его как архив
        $zip = new ZipArchive;
        $zip->open($tmpfilename);
        $column_list_name = 'column.txt';
        //Получаем список колонок
        $columns = explode(',', $zip->getFromName($column_list_name));
        //И проходим по всем файлам архива
        for ($i=0; $i<$zip->numFiles; $i++) {
            $filename = $zip->getNameIndex($i);
            if ($filename!=$column_list_name) {
                $content = json_decode($zip->getFromName($filename));
                var_dump($content); //тут любые манипуляции с содержимым
            }
        }
        //Закрываем файл в самом конце, потому что при закрытии файл удаляется
        fclose($tmp);
    } else {
        //Ожидается ответ в json-е, но сообщение об ошибке приходил в html-е. Поэтому тут просто вывод ответа
        print $resp['content'];
        //Дальше кусок кода для json-а, если это будет исправлено.
        /*$error = json_decode($resp['content']);
        var_dump($resp);
        if (property_exists($error, 'message')) {
            print 'error '.$error->message.PHP_EOL;
        }  else {
            print 'error'.PHP_EOL;
        }
        */
    }
?>
Постановка задания
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php

    function __dopost($url,$data) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $output = curl_exec($ch);
        $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        return array('code'=>$code, 'content'=>$output);
    }

    $apikey = "[API КЛЮЧ]"; // его можно посмотреть на странице http://smartfetch.io/private/profile/
    // Задание - это список ассоциативных массивов Ключ-Значение
    $data = array('task'=>'bingindex',
                  'data'=>json_encode(array('param'=>array(),
                                            'data'=>array(
                                                array(  ),
                                                array(  ),
                                                array(  )
                                             ))));

    $resp = __dopost("http://smartfetch.io/".$apikey."/api2/", $data);
    $response = json_decode($resp['content']);

    if ($response->success) {
        print 'ok '.$response->hash.PHP_EOL;
    }  else {
        if (property_exists($response, 'message')) {
            print 'error '.$response->message.PHP_EOL;
        }  else {
            print 'error '.PHP_EOL;
        }
    }
?>
Получение задания
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php

    function __doget($url) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
        $output = curl_exec($ch);
        $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
         return array('code'=>$code, 'content'=>$output);
    }

    $apikey = "[API КЛЮЧ]"; // его можно посмотреть на странице http://smartfetch.io/private/profile/
    $hash = ИДЕНТИФИКАТОР ЗАДАНИЯ;

    $resp = __doget("http://smartfetch.io/".$apikey."/get/".$hash);

    if ($resp['code']==200) {
        //Создаем временный файл
        $tmp = tmpfile();
        //Записываем в него содержимое zip-архива
        fwrite($tmp, $resp['content']);
        //Получаем путь ко временному файлу
        $si = stream_get_meta_data($tmp);
        $tmpfilename = $si['uri'];
        //И открываем его как архив
        $zip = new ZipArchive;
        $zip->open($tmpfilename);
        $column_list_name = 'column.txt';
        //Получаем список колонок
        $columns = explode(',', $zip->getFromName($column_list_name));
        //И проходим по всем файлам архива
        for ($i=0; $i<$zip->numFiles; $i++) {
            $filename = $zip->getNameIndex($i);
            if ($filename!=$column_list_name) {
                $content = json_decode($zip->getFromName($filename));
                var_dump($content); //тут любые манипуляции с содержимым
            }
        }
        //Закрываем файл в самом конце, потому что при закрытии файл удаляется
        fclose($tmp);
    } else {
        //Ожидается ответ в json-е, но сообщение об ошибке приходил в html-е. Поэтому тут просто вывод ответа
        print $resp['content'];
        //Дальше кусок кода для json-а, если это будет исправлено.
        /*$error = json_decode($resp['content']);
        var_dump($resp);
        if (property_exists($error, 'message')) {
            print 'error '.$error->message.PHP_EOL;
        }  else {
            print 'error'.PHP_EOL;
        }
        */
    }
?>
Постановка задания
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php

    function __dopost($url,$data) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $output = curl_exec($ch);
        $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        return array('code'=>$code, 'content'=>$output);
    }

    $apikey = "[API КЛЮЧ]"; // его можно посмотреть на странице http://smartfetch.io/private/profile/
    // Задание - это список ассоциативных массивов Ключ-Значение
    $data = array('task'=>'bingindex',
                  'data'=>json_encode(array('param'=>array(),
                                            'data'=>array(
                                                array(  ),
                                                array(  ),
                                                array(  )
                                             ))));

    $resp = __dopost("http://smartfetch.io/".$apikey."/api2/", $data);
    $response = json_decode($resp['content']);

    if ($response->success) {
        print 'ok '.$response->hash.PHP_EOL;
    }  else {
        if (property_exists($response, 'message')) {
            print 'error '.$response->message.PHP_EOL;
        }  else {
            print 'error '.PHP_EOL;
        }
    }
?>
Получение задания
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php

    function __doget($url) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
        $output = curl_exec($ch);
        $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
         return array('code'=>$code, 'content'=>$output);
    }

    $apikey = "[API КЛЮЧ]"; // его можно посмотреть на странице http://smartfetch.io/private/profile/
    $hash = ИДЕНТИФИКАТОР ЗАДАНИЯ;

    $resp = __doget("http://smartfetch.io/".$apikey."/get/".$hash);

    if ($resp['code']==200) {
        //Создаем временный файл
        $tmp = tmpfile();
        //Записываем в него содержимое zip-архива
        fwrite($tmp, $resp['content']);
        //Получаем путь ко временному файлу
        $si = stream_get_meta_data($tmp);
        $tmpfilename = $si['uri'];
        //И открываем его как архив
        $zip = new ZipArchive;
        $zip->open($tmpfilename);
        $column_list_name = 'column.txt';
        //Получаем список колонок
        $columns = explode(',', $zip->getFromName($column_list_name));
        //И проходим по всем файлам архива
        for ($i=0; $i<$zip->numFiles; $i++) {
            $filename = $zip->getNameIndex($i);
            if ($filename!=$column_list_name) {
                $content = json_decode($zip->getFromName($filename));
                var_dump($content); //тут любые манипуляции с содержимым
            }
        }
        //Закрываем файл в самом конце, потому что при закрытии файл удаляется
        fclose($tmp);
    } else {
        //Ожидается ответ в json-е, но сообщение об ошибке приходил в html-е. Поэтому тут просто вывод ответа
        print $resp['content'];
        //Дальше кусок кода для json-а, если это будет исправлено.
        /*$error = json_decode($resp['content']);
        var_dump($resp);
        if (property_exists($error, 'message')) {
            print 'error '.$error->message.PHP_EOL;
        }  else {
            print 'error'.PHP_EOL;
        }
        */
    }
?>
Постановка задания
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php

    function __dopost($url,$data) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $output = curl_exec($ch);
        $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        return array('code'=>$code, 'content'=>$output);
    }

    $apikey = "[API КЛЮЧ]"; // его можно посмотреть на странице http://smartfetch.io/private/profile/
    // Задание - это список ассоциативных массивов Ключ-Значение
    $data = array('task'=>'bingindex',
                  'data'=>json_encode(array('param'=>array(),
                                            'data'=>array(
                                                array(  ),
                                                array(  ),
                                                array(  )
                                             ))));

    $resp = __dopost("http://smartfetch.io/".$apikey."/api2/", $data);
    $response = json_decode($resp['content']);

    if ($response->success) {
        print 'ok '.$response->hash.PHP_EOL;
    }  else {
        if (property_exists($response, 'message')) {
            print 'error '.$response->message.PHP_EOL;
        }  else {
            print 'error '.PHP_EOL;
        }
    }
?>
Получение задания
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php

    function __doget($url) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
        $output = curl_exec($ch);
        $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
         return array('code'=>$code, 'content'=>$output);
    }

    $apikey = "[API КЛЮЧ]"; // его можно посмотреть на странице http://smartfetch.io/private/profile/
    $hash = ИДЕНТИФИКАТОР ЗАДАНИЯ;

    $resp = __doget("http://smartfetch.io/".$apikey."/get/".$hash);

    if ($resp['code']==200) {
        //Создаем временный файл
        $tmp = tmpfile();
        //Записываем в него содержимое zip-архива
        fwrite($tmp, $resp['content']);
        //Получаем путь ко временному файлу
        $si = stream_get_meta_data($tmp);
        $tmpfilename = $si['uri'];
        //И открываем его как архив
        $zip = new ZipArchive;
        $zip->open($tmpfilename);
        $column_list_name = 'column.txt';
        //Получаем список колонок
        $columns = explode(',', $zip->getFromName($column_list_name));
        //И проходим по всем файлам архива
        for ($i=0; $i<$zip->numFiles; $i++) {
            $filename = $zip->getNameIndex($i);
            if ($filename!=$column_list_name) {
                $content = json_decode($zip->getFromName($filename));
                var_dump($content); //тут любые манипуляции с содержимым
            }
        }
        //Закрываем файл в самом конце, потому что при закрытии файл удаляется
        fclose($tmp);
    } else {
        //Ожидается ответ в json-е, но сообщение об ошибке приходил в html-е. Поэтому тут просто вывод ответа
        print $resp['content'];
        //Дальше кусок кода для json-а, если это будет исправлено.
        /*$error = json_decode($resp['content']);
        var_dump($resp);
        if (property_exists($error, 'message')) {
            print 'error '.$error->message.PHP_EOL;
        }  else {
            print 'error'.PHP_EOL;
        }
        */
    }
?>
Постановка задания
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php

    function __dopost($url,$data) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $output = curl_exec($ch);
        $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        return array('code'=>$code, 'content'=>$output);
    }

    $apikey = "[API КЛЮЧ]"; // его можно посмотреть на странице http://smartfetch.io/private/profile/
    // Задание - это список ассоциативных массивов Ключ-Значение
    $data = array('task'=>'bingindex',
                  'data'=>json_encode(array('param'=>array(),
                                            'data'=>array(
                                                array(  ),
                                                array(  ),
                                                array(  )
                                             ))));

    $resp = __dopost("http://smartfetch.io/".$apikey."/api2/", $data);
    $response = json_decode($resp['content']);

    if ($response->success) {
        print 'ok '.$response->hash.PHP_EOL;
    }  else {
        if (property_exists($response, 'message')) {
            print 'error '.$response->message.PHP_EOL;
        }  else {
            print 'error '.PHP_EOL;
        }
    }
?>
Получение задания
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php

    function __doget($url) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
        $output = curl_exec($ch);
        $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
         return array('code'=>$code, 'content'=>$output);
    }

    $apikey = "[API КЛЮЧ]"; // его можно посмотреть на странице http://smartfetch.io/private/profile/
    $hash = ИДЕНТИФИКАТОР ЗАДАНИЯ;

    $resp = __doget("http://smartfetch.io/".$apikey."/get/".$hash);

    if ($resp['code']==200) {
        //Создаем временный файл
        $tmp = tmpfile();
        //Записываем в него содержимое zip-архива
        fwrite($tmp, $resp['content']);
        //Получаем путь ко временному файлу
        $si = stream_get_meta_data($tmp);
        $tmpfilename = $si['uri'];
        //И открываем его как архив
        $zip = new ZipArchive;
        $zip->open($tmpfilename);
        $column_list_name = 'column.txt';
        //Получаем список колонок
        $columns = explode(',', $zip->getFromName($column_list_name));
        //И проходим по всем файлам архива
        for ($i=0; $i<$zip->numFiles; $i++) {
            $filename = $zip->getNameIndex($i);
            if ($filename!=$column_list_name) {
                $content = json_decode($zip->getFromName($filename));
                var_dump($content); //тут любые манипуляции с содержимым
            }
        }
        //Закрываем файл в самом конце, потому что при закрытии файл удаляется
        fclose($tmp);
    } else {
        //Ожидается ответ в json-е, но сообщение об ошибке приходил в html-е. Поэтому тут просто вывод ответа
        print $resp['content'];
        //Дальше кусок кода для json-а, если это будет исправлено.
        /*$error = json_decode($resp['content']);
        var_dump($resp);
        if (property_exists($error, 'message')) {
            print 'error '.$error->message.PHP_EOL;
        }  else {
            print 'error'.PHP_EOL;
        }
        */
    }
?>
Постановка задания
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php

    function __dopost($url,$data) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $output = curl_exec($ch);
        $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        return array('code'=>$code, 'content'=>$output);
    }

    $apikey = "[API КЛЮЧ]"; // его можно посмотреть на странице http://smartfetch.io/private/profile/
    // Задание - это список ассоциативных массивов Ключ-Значение
    $data = array('task'=>'bingindex',
                  'data'=>json_encode(array('param'=>array(),
                                            'data'=>array(
                                                array(  ),
                                                array(  ),
                                                array(  )
                                             ))));

    $resp = __dopost("http://smartfetch.io/".$apikey."/api2/", $data);
    $response = json_decode($resp['content']);

    if ($response->success) {
        print 'ok '.$response->hash.PHP_EOL;
    }  else {
        if (property_exists($response, 'message')) {
            print 'error '.$response->message.PHP_EOL;
        }  else {
            print 'error '.PHP_EOL;
        }
    }
?>
Получение задания
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php

    function __doget($url) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
        $output = curl_exec($ch);
        $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
         return array('code'=>$code, 'content'=>$output);
    }

    $apikey = "[API КЛЮЧ]"; // его можно посмотреть на странице http://smartfetch.io/private/profile/
    $hash = ИДЕНТИФИКАТОР ЗАДАНИЯ;

    $resp = __doget("http://smartfetch.io/".$apikey."/get/".$hash);

    if ($resp['code']==200) {
        //Создаем временный файл
        $tmp = tmpfile();
        //Записываем в него содержимое zip-архива
        fwrite($tmp, $resp['content']);
        //Получаем путь ко временному файлу
        $si = stream_get_meta_data($tmp);
        $tmpfilename = $si['uri'];
        //И открываем его как архив
        $zip = new ZipArchive;
        $zip->open($tmpfilename);
        $column_list_name = 'column.txt';
        //Получаем список колонок
        $columns = explode(',', $zip->getFromName($column_list_name));
        //И проходим по всем файлам архива
        for ($i=0; $i<$zip->numFiles; $i++) {
            $filename = $zip->getNameIndex($i);
            if ($filename!=$column_list_name) {
                $content = json_decode($zip->getFromName($filename));
                var_dump($content); //тут любые манипуляции с содержимым
            }
        }
        //Закрываем файл в самом конце, потому что при закрытии файл удаляется
        fclose($tmp);
    } else {
        //Ожидается ответ в json-е, но сообщение об ошибке приходил в html-е. Поэтому тут просто вывод ответа
        print $resp['content'];
        //Дальше кусок кода для json-а, если это будет исправлено.
        /*$error = json_decode($resp['content']);
        var_dump($resp);
        if (property_exists($error, 'message')) {
            print 'error '.$error->message.PHP_EOL;
        }  else {
            print 'error'.PHP_EOL;
        }
        */
    }
?>