### Perform GET Requests with Crawlbase CrawlingAPI Source: https://github.com/crawlbase/crawlbase-php/blob/main/README.md Demonstrates how to make GET requests using the Crawlbase CrawlingAPI. It covers the method signature, basic usage, passing various options like user agent and format, and enabling storage of responses in Crawlbase Cloud Storage. ```APIDOC Crawlbase\CrawlingAPI::get(string $url, array $options = []) - Description: Sends a GET request to the specified URL. - Parameters: - $url (string): The URL to scrape. - $options (array): An associative array of additional Crawlbase API parameters (e.g., 'user_agent', 'format', 'store'). - Returns: A response object with properties like 'statusCode', 'body', and 'headers'. ``` ```php $response = $api->get('https://www.facebook.com/britneyspears'); if ($response->statusCode === 200) { echo $response->body; } ``` ```php $response = $api->get('https://www.reddit.com/r/pics/comments/5bx4bx/thanks_obama/', [ 'user_agent' => 'Mozilla/5.0 (Windows NT 6.2; rv:20.0) Gecko/20121202 Firefox/30.0', 'format' => 'json' ]); if ($response->statusCode === 200) { echo $response->body; } ``` ```php $response = $api->get('https://www.reddit.com/r/pics/comments/5bx4bx/thanks_obama/', [ 'store' => true ]); if ($response->statusCode === 200) { echo 'storage url: ' . $response->headers->storage_url . PHP_EOL; } ``` -------------------------------- ### Capture Screenshots with Crawlbase Screenshots API in PHP Source: https://github.com/crawlbase/crawlbase-php/blob/main/README.md Illustrates how to initialize the Crawlbase Screenshots API and capture a screenshot from a URL. It provides examples for saving the screenshot directly to a file, using a callback function to handle the file path, and specifying a save path with a callback for more control. ```php $api = new Crawlbase\ScreenshotsAPI(['token' => 'YOUR_TOKEN']); ``` ```php $api = new Crawlbase\ScreenshotsAPI(['token' => 'YOUR_TOKEN']); $response = $api->get('https://www.apple.com'); echo 'success: ' . $response->headers->success . PHP_EOL; echo 'remaining requests: ' . $response->headers->remaining_requests . PHP_EOL; file_put_contents('apple.jpg', $response->body); ``` ```php $api = new Crawlbase\ScreenshotsAPI(['token' => 'YOUR_TOKEN']); $response = $api->get('https://www.apple.com', [ 'callback' => function($filepath) { echo 'filepath: ' . $filepath . PHP_EOL; } ]); echo 'success: ' . $response->headers->success . PHP_EOL; echo 'remaining requests: ' . $response->headers->remaining_requests . PHP_EOL; ``` ```php $api = new Crawlbase\ScreenshotsAPI(['token' => 'YOUR_TOKEN']); $response = $api->get('https://www.apple.com', [ 'saveToPath' => 'apple.jpg', 'callback' => function($filepath) { echo 'filepath: ' . $filepath . PHP_EOL; } ]); echo 'success: ' . $response->headers->success . PHP_EOL; echo 'remaining requests: ' . $response->headers->remaining_requests . PHP_EOL; ``` -------------------------------- ### Initialize and Use Crawlbase ScraperAPI Source: https://github.com/crawlbase/crawlbase-php/blob/main/README.md Initializes the ScraperAPI class with your token for scraping specific websites that are supported by Crawlbase's structured data extraction. It demonstrates making a GET request and parsing the JSON response for structured data. ```php $api = new Crawlbase\ScraperAPI(['token' => 'YOUR_TOKEN']); ``` ```php $response = $api->get('https://www.amazon.com/DualSense-Wireless-Controller-PlayStation-5/dp/B08FC6C75Y/'); echo 'status code: ' . $response->statusCode . PHP_EOL; if ($response->statusCode === 200) { var_dump($response->json); // Will print scraped Amazon details } ``` -------------------------------- ### Manage Stored Data with Crawlbase Storage API in PHP Source: https://github.com/crawlbase/crawlbase-php/blob/main/README.md Covers the initialization of the Crawlbase Storage API and various operations including retrieving stored data by URL or RID, deleting items, performing bulk retrievals, listing RIDs from your storage area, and getting the total count of stored items. ```php $api = new Crawlbase\StorageAPI(['token' => 'YOUR_TOKEN']); ``` ```php $response = $api->get('https://www.apple.com'); echo 'status code: ' . $response->statusCode . PHP_EOL; if ($response->statusCode === 200) { echo 'body: ' . $response->body . PHP_EOL; echo 'original status: ' . $response->headers->original_status . PHP_EOL; echo 'crawlbase status: ' . $response->headers->pc_status . PHP_EOL; echo 'rid: ' . $response->headers->rid . PHP_EOL; echo 'url: ' . $response->headers->url . PHP_EOL; echo 'stored date: ' . $response->headers->stored_at . PHP_EOL; } ``` ```php $response = $api->get('RID_REPLACE'); echo 'status code: ' . $response->statusCode . PHP_EOL; if ($response->statusCode === 200) { echo 'body: ' . $response->body . PHP_EOL; echo 'original status: ' . $response->headers->original_status . PHP_EOL; echo 'crawlbase status: ' . $response->headers->pc_status . PHP_EOL; echo 'rid: ' . $response->headers->rid . PHP_EOL; echo 'url: ' . $response->headers->url . PHP_EOL; echo 'stored date: ' . $response->headers->stored_at . PHP_EOL; } ``` ```php if ($api->delete('RID_REPLACE')) { echo 'delete success' . PHP_EOL; echo 'status code: ' . $api->response->statusCode . PHP_EOL; } else { echo 'delete failed' . PHP_EOL; echo 'status code: ' . $api->response->statusCode . PHP_EOL; } ``` ```php $items = $api->bulk(['RID1', 'RID2', 'RID3', ...]); foreach ($items as $item) { echo 'body: ' . $item->body . PHP_EOL; echo 'stored at: ' . $item->stored_at . PHP_EOL; echo 'original status: ' . $item->original_status . PHP_EOL; echo 'crawlbase status: ' . $item->pc_status . PHP_EOL; echo 'rid: ' . $item->rid . PHP_EOL; echo 'url: ' . $item->url . PHP_EOL; echo PHP_EOL; } ``` ```php $rids = $api->rids(); foreach ($rids as $rid) { echo $rid . PHP_EOL; } ``` ```php $rids = $api->rids(10); ``` ```php $totalCount = $api->totalCount(); echo 'total count: ' . $totalCount . PHP_EOL; ``` -------------------------------- ### Perform POST Requests with Crawlbase CrawlingAPI Source: https://github.com/crawlbase/crawlbase-php/blob/main/README.md Illustrates how to send POST requests using the Crawlbase CrawlingAPI. Examples include sending form-urlencoded data and JSON data by specifying the `post_content_type` option. ```APIDOC Crawlbase\CrawlingAPI::post(string $url, array or string $data, array $options = []) - Description: Sends a POST request to the specified URL. - Parameters: - $url (string): The URL to send the POST request to. - $data (array|string): The data to send. Can be an associative array for form-urlencoded or a JSON string. - $options (array): An associative array of additional Crawlbase API parameters, e.g., 'post_content_type' to 'json'. - Returns: A response object with properties like 'statusCode', 'body', and 'headers'. ``` ```php $response = $api->post('https://producthunt.com/search', ['text' => 'example search']); if ($response->statusCode === 200) { echo $response->body; } ``` ```php $response = $api->post('https://httpbin.org/post', json_encode(['some_json' => 'with some value']), ['post_content_type' => 'json']); if ($response->statusCode === 200) { echo $response->body; } ``` -------------------------------- ### Perform Javascript-Rendered Page Requests with Crawlbase CrawlingAPI Source: https://github.com/crawlbase/crawlbase-php/blob/main/README.md Explains how to scrape JavaScript-rendered websites (e.g., React, Angular, Vue) using a dedicated JavaScript token. It demonstrates initializing the API with the JavaScript token and making GET requests with optional parameters like `page_wait`. ```php $api = new Crawlbase\CrawlingAPI(['token' => 'YOUR_JAVASCRIPT_TOKEN']); ``` ```php $response = $api->get('https://www.nfl.com'); if ($response->statusCode === 200) { echo $response->body; } ``` ```php $response = $api->get('https://www.freelancer.com', ['page_wait' => 5000]); if ($response->statusCode === 200) { echo $response->body; } ``` -------------------------------- ### Initialize and Use Crawlbase Leads API in PHP Source: https://github.com/crawlbase/crawlbase-php/blob/main/README.md Demonstrates how to initialize the Crawlbase Leads API with an authentication token and retrieve leads from a specified domain. It then iterates through the returned leads to print their email addresses, checking for a successful API response. ```php $api = new Crawlbase\LeadsAPI(['token' => 'YOUR_TOKEN']); ``` ```php $response = $api->getFromDomain('target.com'); if ($response->statusCode === 200) { foreach ($response->json->leads as $key => $lead) { echo $lead->email . PHP_EOL; } } ``` -------------------------------- ### Initialize Crawlbase CrawlingAPI Source: https://github.com/crawlbase/crawlbase-php/blob/main/README.md Initializes the CrawlingAPI class with your authentication token. This token is essential for making requests to the Crawlbase API and can be obtained from the Crawlbase website. ```php $api = new Crawlbase\CrawlingAPI(['token' => 'YOUR_TOKEN']); ``` -------------------------------- ### Perform PUT Requests with Crawlbase CrawlingAPI Source: https://github.com/crawlbase/crawlbase-php/blob/main/README.md Shows how to make PUT requests using the Crawlbase CrawlingAPI, demonstrating sending data similar to POST requests. ```APIDOC Crawlbase\CrawlingAPI::put(string $url, array or string $data, array $options = []) - Description: Sends a PUT request to the specified URL. - Parameters: - $url (string): The URL to send the PUT request to. - $data (array|string): The data to send. Can be an associative array or a string. - $options (array): An associative array of additional Crawlbase API parameters. - Returns: A response object with properties like 'statusCode', 'body', and 'headers'. ``` ```php $response = $api->put('https://producthunt.com/search', ['text' => 'example search']); if ($response->statusCode === 200) { echo $response->body; } ``` -------------------------------- ### Retrieve Original and Crawlbase Status Codes Source: https://github.com/crawlbase/crawlbase-php/blob/main/README.md Shows how to access the original HTTP status code of the target website and the Crawlbase processing status from the response headers after a request. ```php $response = $api->get('https://craiglist.com'); echo $response->headers->original_status . PHP_EOL; echo $response->headers->pc_status . PHP_EOL; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.