{"id":18610568,"url":"https://github.com/ixnode/php-web-crawler","last_synced_at":"2025-11-02T21:30:24.576Z","repository":{"id":224209146,"uuid":"762721684","full_name":"ixnode/php-web-crawler","owner":"ixnode","description":"This PHP class allows you to crawl recursively a given html page (or a given html file) and collect some data from it.","archived":false,"fork":false,"pushed_at":"2024-02-28T01:18:31.000Z","size":209,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-27T01:41:38.555Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ixnode.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-24T14:07:40.000Z","updated_at":"2024-02-25T00:05:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"9b5a7cab-ad9c-43fd-a5ad-4fd4e2bb08d2","html_url":"https://github.com/ixnode/php-web-crawler","commit_stats":null,"previous_names":["ixnode/php-web-crawler"],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ixnode%2Fphp-web-crawler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ixnode%2Fphp-web-crawler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ixnode%2Fphp-web-crawler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ixnode%2Fphp-web-crawler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ixnode","download_url":"https://codeload.github.com/ixnode/php-web-crawler/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239400606,"owners_count":19632051,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T03:11:05.384Z","updated_at":"2025-11-02T21:30:24.522Z","avatar_url":"https://github.com/ixnode.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP Web Crawler\n\n[![Release](https://img.shields.io/github/v/release/ixnode/php-web-crawler)](https://github.com/ixnode/php-web-crawler/releases)\n[![](https://img.shields.io/github/release-date/ixnode/php-web-crawler)](https://github.com/ixnode/php-web-crawler/releases)\n![](https://img.shields.io/github/repo-size/ixnode/php-web-crawler.svg)\n[![PHP](https://img.shields.io/badge/PHP-^8.2-777bb3.svg?logo=php\u0026logoColor=white\u0026labelColor=555555\u0026style=flat)](https://www.php.net/supported-versions.php)\n[![PHPStan](https://img.shields.io/badge/PHPStan-Level%20Max-777bb3.svg?style=flat)](https://phpstan.org/user-guide/rule-levels)\n[![PHPUnit](https://img.shields.io/badge/PHPUnit-Unit%20Tests-6b9bd2.svg?style=flat)](https://phpunit.de)\n[![PHPCS](https://img.shields.io/badge/PHPCS-PSR12-416d4e.svg?style=flat)](https://www.php-fig.org/psr/psr-12/)\n[![PHPMD](https://img.shields.io/badge/PHPMD-ALL-364a83.svg?style=flat)](https://github.com/phpmd/phpmd)\n[![Rector - Instant Upgrades and Automated Refactoring](https://img.shields.io/badge/Rector-PHP%208.2-73a165.svg?style=flat)](https://github.com/rectorphp/rector)\n[![LICENSE](https://img.shields.io/github/license/ixnode/php-api-version-bundle)](https://github.com/ixnode/php-api-version-bundle/blob/master/LICENSE)\n\n\u003e This PHP class allows you to crawl recursively a given html page (or a given html file) and collect some data from it.\n\u003e Simply define the url (or a html file) and a set of xpath expressions which should map with the output data object.\n\u003e The final representation will be a php array which can be easily converted into the json format for further\n\u003e processing.\n\n## 1. Installation\n\n```shell\ncomposer require ixnode/php-web-crawler\n```\n\n```shell\nvendor/bin/php-web-crawler -V\n```\n\n```shell\nphp-web-crawler 0.1.0 (02-24-2024 14:46:26) - Björn Hempel \u003cbjoern@hempel.li\u003e\n```\n\n## 2. Usage\n\n### 2.1 PHP Code\n\n```php\nuse Ixnode\\PhpWebCrawler\\Output\\Field;\nuse Ixnode\\PhpWebCrawler\\Source\\Raw;\nuse Ixnode\\PhpWebCrawler\\Value\\Text;\nuse Ixnode\\PhpWebCrawler\\Value\\XpathTextNode;\n\n$rawHtml = \u003c\u003c\u003cHTML\n\u003chtml\u003e\n    \u003chead\u003e\n        \u003ctitle\u003eTest Page\u003c/title\u003e\n    \u003c/head\u003e\n    \u003cbody\u003e\n        \u003ch1\u003eTest Title\u003c/h1\u003e\n        \u003cp\u003eTest Paragraph\u003c/p\u003e\n    \u003c/body\u003e\n\u003c/html\u003e\nHTML;\n\n$html = new Raw(\n    $rawHtml,\n    new Field('version', new Text('1.0.0')),\n    new Field('title', new XpathTextNode('//h1')),\n    new Field('paragraph', new XpathTextNode('//p'))\n);\n\n$html-\u003eparse()-\u003egetJsonStringFormatted();\n// See below\n```\n\n### 2.2 JSON result\n\n```json\n{\n    \"version\": \"1.0.0\",\n    \"title\": \"Test Title\",\n    \"paragraph\": \"Test Paragraph\"\n}\n```\n\n## 3. Advanced usage\n\n### 3.1 Group\n\n#### PHP Code\n\n```php\nuse Ixnode\\PhpWebCrawler\\Output\\Field;\nuse Ixnode\\PhpWebCrawler\\Output\\Group;\nuse Ixnode\\PhpWebCrawler\\Source\\Raw;\nuse Ixnode\\PhpWebCrawler\\Value\\XpathTextNode;\n\n$rawHtml = \u003c\u003c\u003cHTML\n\u003chtml\u003e\n    \u003chead\u003e\n        \u003ctitle\u003eTest Page\u003c/title\u003e\n    \u003c/head\u003e\n    \u003cbody\u003e\n        \u003ch1\u003eTest Title\u003c/h1\u003e\n        \u003cp class=\"paragraph-1\"\u003eTest Paragraph 1\u003c/p\u003e\n        \u003cp class=\"paragraph-2\"\u003eTest Paragraph 2\u003c/p\u003e\n    \u003c/body\u003e\n\u003c/html\u003e\nHTML;\n\n$html = new Raw(\n    $rawHtml,\n    new Field('title', new XpathTextNode('/html/head/title')),\n    new Group(\n        'content',\n        new Group(\n            'header',\n            new Field('h1', new XpathTextNode('/html/body//h1')),\n        ),\n        new Group(\n            'text',\n            new Field('p1', new XpathTextNode('/html/body//p[@class=\"paragraph-1\"]')),\n            new Field('p2', new XpathTextNode('/html/body//p[@class=\"paragraph-2\"]')),\n        )\n    )\n);\n\n$html-\u003eparse()-\u003egetJsonStringFormatted();\n// See below\n```\n\n#### JSON result\n\n```json\n{\n  \"title\": \"Test Page\",\n  \"content\": {\n    \"header\": {\n      \"h1\": \"Test Title\"\n    },\n    \"text\": {\n      \"p1\": \"Test Paragraph 1\",\n      \"p2\": \"Test Paragraph 2\"\n    }\n  }\n}\n```\n\n### 3.2 XpathSection\n\n#### PHP Code\n\n```php\nuse Ixnode\\PhpWebCrawler\\Output\\Field;\nuse Ixnode\\PhpWebCrawler\\Output\\Group;\nuse Ixnode\\PhpWebCrawler\\Source\\Raw;\nuse Ixnode\\PhpWebCrawler\\Source\\XpathSection;\nuse Ixnode\\PhpWebCrawler\\Value\\XpathTextNode;\n\n$rawHtml = \u003c\u003c\u003cHTML\n\u003chtml\u003e\n    \u003chead\u003e\n        \u003ctitle\u003eTest Page\u003c/title\u003e\n    \u003c/head\u003e\n    \u003cbody\u003e\n        \u003cdiv class=\"content\"\u003e\n            \u003ch1\u003eTest Title\u003c/h1\u003e\n            \u003cp class=\"paragraph-1\"\u003eTest Paragraph 1\u003c/p\u003e\n            \u003cp class=\"paragraph-2\"\u003eTest Paragraph 2\u003c/p\u003e\n        \u003c/div\u003e\n    \u003c/body\u003e\n\u003c/html\u003e\nHTML;\n\n$html = new Raw(\n    $rawHtml,\n    new Field('title', new XpathTextNode('/html/head/title')),\n    new Group(\n        'content',\n        new XpathSection(\n            '/html/body//div[@class=\"content\"]',\n            new Group(\n                'header',\n                new Field('h1', new XpathTextNode('./h1')),\n            ),\n            new Group(\n                'text',\n                new Field('p1', new XpathTextNode('./p[@class=\"paragraph-1\"]')),\n                new Field('p2', new XpathTextNode('./p[@class=\"paragraph-2\"]')),\n            )\n        )\n    )\n);\n\n$html-\u003eparse()-\u003egetJsonStringFormatted();\n// See below\n```\n\n#### JSON result\n\n```json\n{\n    \"title\": \"Test Page\",\n    \"content\": {\n        \"header\": {\n            \"h1\": \"Test Title\"\n        },\n        \"text\": {\n            \"p1\": \"Test Paragraph 1\",\n            \"p2\": \"Test Paragraph 2\"\n        }\n    }\n}\n```\n\n### 3.3 XpathSection (flat)\n\n#### PHP Code\n\n```php\nuse Ixnode\\PhpWebCrawler\\Output\\Field;\nuse Ixnode\\PhpWebCrawler\\Output\\Group;\nuse Ixnode\\PhpWebCrawler\\Source\\Raw;\nuse Ixnode\\PhpWebCrawler\\Source\\XpathSections;\nuse Ixnode\\PhpWebCrawler\\Value\\XpathTextNode;\n\n$rawHtml = \u003c\u003c\u003cHTML\n\u003chtml\u003e\n    \u003chead\u003e\n        \u003ctitle\u003eTest Page\u003c/title\u003e\n    \u003c/head\u003e\n    \u003cbody\u003e\n        \u003cdiv class=\"content\"\u003e\n            \u003ch1\u003eTest Title\u003c/h1\u003e\n            \u003cp class=\"paragraph-1\"\u003eTest Paragraph 1\u003c/p\u003e\n            \u003cp class=\"paragraph-2\"\u003eTest Paragraph 2\u003c/p\u003e\n            \u003cul\u003e\n                \u003cli\u003eTest Item 1\u003c/li\u003e\n                \u003cli\u003eTest Item 2\u003c/li\u003e\n            \u003c/ul\u003e\n        \u003c/div\u003e\n    \u003c/body\u003e\n\u003c/html\u003e\nHTML;\n\n$html = new Raw(\n    $rawHtml,\n    new Field('title', new XpathTextNode('/html/head/title')),\n    new Group(\n        'hits',\n        new XpathSections(\n            '/html/body//div[@class=\"content\"]/ul',\n            new XpathTextNode('./li/text()'),\n        )\n    )\n);\n\n$html-\u003eparse()-\u003egetJsonStringFormatted();\n// See below\n```\n\n#### JSON result\n\n```json\n{\n    \"title\": \"Test Page\",\n    \"hits\": [\n        [\n            \"Test Item 1\",\n            \"Test Item 2\"\n        ]\n    ]\n}\n```\n\n### 3.3 XpathSection (structured)\n\n#### PHP Code\n\n```php\nuse Ixnode\\PhpWebCrawler\\Output\\Field;\nuse Ixnode\\PhpWebCrawler\\Output\\Group;\nuse Ixnode\\PhpWebCrawler\\Source\\Raw;\nuse Ixnode\\PhpWebCrawler\\Source\\XpathSections;\nuse Ixnode\\PhpWebCrawler\\Value\\XpathTextNode;\n\n$rawHtml = \u003c\u003c\u003cHTML\n\u003chtml\u003e\n    \u003chead\u003e\n        \u003ctitle\u003eTest Page\u003c/title\u003e\n    \u003c/head\u003e\n    \u003cbody\u003e\n        \u003cdiv class=\"content\"\u003e\n            \u003ch1\u003eTest Title\u003c/h1\u003e\n            \u003cp class=\"paragraph-1\"\u003eTest Paragraph 1\u003c/p\u003e\n            \u003cp class=\"paragraph-2\"\u003eTest Paragraph 2\u003c/p\u003e\n            \u003ctable\u003e\n                \u003ctbody\u003e\n                    \u003ctr\u003e\n                        \u003cth\u003eCaption 1\u003c/th\u003e\n                        \u003ctd\u003eCell 1\u003c/td\u003e\n                    \u003c/tr\u003e\n                    \u003ctr\u003e\n                        \u003cth\u003eCaption 2\u003c/th\u003e\n                        \u003ctd\u003eCell 2\u003c/td\u003e\n                    \u003c/tr\u003e\n                \u003c/tbody\u003e\n            \u003c/table\u003e\n        \u003c/div\u003e\n    \u003c/body\u003e\n\u003c/html\u003e\nHTML;\n\n$html = new Raw(\n    $rawHtml,\n    new Field('title', new XpathTextNode('/html/head/title')),\n    new Group(\n        'hits',\n        new XpathSections(\n            '/html/body//div[@class=\"content\"]/table/tbody/tr',\n            new Field('caption', new XpathTextNode('./th/text()')),\n            new Field('content', new XpathTextNode('./td/text()')),\n        )\n    )\n);\n\n$html-\u003eparse()-\u003egetJsonStringFormatted();\n// See below\n```\n\n#### JSON result\n\n```json\n{\n    \"title\": \"Test Page\",\n    \"hits\": [\n        {\n            \"caption\": \"Caption 1\",\n            \"content\": \"Cell 1\"\n        },\n        {\n            \"caption\": \"Caption 2\",\n            \"content\": \"Cell 2\"\n        }\n    ]\n}\n```\n\n## 4. More examples\n\n* [examples/converter.php](examples/converter.php)\n* [examples/group.php](examples/group.php)\n* [examples/section.php](examples/section.php)\n* [examples/sections-recursive-url.php](examples/sections-recursive-url.php)\n* [examples/sections.php](examples/sections.php)\n* [examples/simple-wiki-page.php](examples/simple-wiki-page.php)\n\n## 5. Development\n\n```bash\ngit clone git@github.com:ixnode/php-web-crawler.git \u0026\u0026 cd php-web-crawler\n```\n\n```bash\ncomposer install\n```\n\n```bash\ncomposer test\n```\n\n## 6. License\n\nThis library is licensed under the MIT License - see the [LICENSE.md](/LICENSE.md) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fixnode%2Fphp-web-crawler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fixnode%2Fphp-web-crawler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fixnode%2Fphp-web-crawler/lists"}