PHP code example of nueip / curl

1. Go to this page and download the library: Download nueip/curl library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nueip / curl example snippets


$config = [
  // Title for recognize
  title => '',
  // Targe url
  url => '',
  // Request method
  type => '',
  // Request argements
  data => [],
  // Extra curl options
  curlOpt => [],
  // Cookie content
  cookies => [],
];

// Set config
$config = new CrawlerConfig([
  'title' => '',
  'url' => '',
  'type' => '',
  'data' => [],
  'curlOpt' => [],
  'cookies' => [],
]);

// Execute crawler
$result = Crawler::run($config)

    $config = new CrawlerConfig([
      'title' => 'List all data',
      'url' => 'https://example.com/tests/fakeWeb/index.php',
      'type' => 'get',
    ]);

    $result = Crawler::run($config);
    

    $result = [
      'code' => 200,
      'message' => 'success',
      'data' => [
        '5241' => [
          'id' => 5241,
          'username' => 'admin',
          'password' => '123456',
          'email' => '[email protected]'
        ],
        '6542' => [
          'id' => 6542,
          'username' => 'user1',
          'password' => 'user1_pass',
          'email' => '[email protected]'
        ],
        '6543' => [
          'id' => 6543,
          'username' => 'user2',
          'password' => 'user2_pass',
          'email' => '[email protected]'
        ]
      ]
    ];
    

    $config = new CrawlerConfig([
      'title' => 'List someone member',
      'url' => 'https://example.com/tests/fakeWeb/index.php?id=6543',
      'type' => 'get',
    ]);

    $result = Crawler::run($config);
    

    $result = [
      'code' => 200,
      'message' => 'success',
      'data' => [
        'id' => 6543,
        'username' => 'user2',
        'password' => 'user2_pass',
        'email' => '[email protected]'
      ]
    ];
    

    $config = new CrawlerConfig([
      'title' => 'Login',
      'url' => 'https://example.com/tests/fakeWeb/index.php',
      'type' => 'post',
      'data' => [
        'username' => 'admin',
        'password' => '123456',
      ]
    ]);

    $result = Crawler::run($config);
    

    $result = [
      'code' => 200,
      'message' => 'Login success',
    ];
    

    $config = new CrawlerConfig([
      'title' => 'Edit data',
      'url' => 'https://example.com/tests/fakeWeb/index.php',
      'type' => 'put',
      'data' => [
        'id' => '1234',
        'email' => '[email protected]',
      ],
    ]);

    $result = Crawler::run($config);
    

    $result = [
      'code' => 200,
      'message' => 'success',
      'data' => [
        'id' => '1234',
        'email' => '[email protected]',
        'username' => 'admin',
        'password' => '123456'
      ]
    ];