{"id":325610,"date":"2021-06-28T15:00:23","date_gmt":"2021-06-28T15:00:23","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=325610"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=325610","title":{"rendered":"\u0412\u0435\u0431-\u0441\u043a\u0440\u0435\u0439\u043f\u0438\u043d\u0433 \u043d\u0430 PHP"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/1e\/ns\/9s\/1ens9snce7hfihupglqn8956c3i.jpeg\" width=\"350\"><\/div>\n<p>  \u0422\u0435\u0440\u043c\u0438\u043d <i>web scraping<\/i> \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0438\u0437 \u0432\u0435\u0431-\u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435. \u0415\u0433\u043e \u0435\u0449\u0451 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 <i>web crawling<\/i> \u0438\u043b\u0438 <i>web data extraction<\/i>.<\/p>\n<p>  PHP \u0448\u0438\u0440\u043e\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0433\u043e \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0441\u0430\u0439\u0442\u043e\u0432 \u0438 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439. \u0418 \u043d\u0430 \u043d\u0451\u043c \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0435\u0431-\u0441\u043a\u0440\u0435\u0439\u043f\u0435\u0440. \u041d\u043e \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u043d\u0435 \u0445\u043e\u0442\u0438\u043c \u0438\u0437\u043e\u0431\u0440\u0435\u0442\u0430\u0442\u044c \u043a\u043e\u043b\u0435\u0441\u043e, \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0433\u043e\u0442\u043e\u0432\u044b\u043c\u0438 open-source \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c\u0438 \u0434\u043b\u044f \u0432\u0435\u0431-\u0441\u043a\u0440\u0435\u0439\u043f\u0438\u043d\u0433\u0430. \u041a\u0441\u0442\u0430\u0442\u0438, \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u043e\u0442\u043b\u0438\u0447\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e \u043f\u0440\u043e <a href=\"https:\/\/www.scrapingdog.com\/blog\/web-scraping-101-with-nodejs.html\">\u0432\u0435\u0431-\u0441\u043a\u0440\u0435\u0439\u043f\u0438\u043d\u0433 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Node.js<\/a> \u0438 <a href=\"https:\/\/www.scrapingdog.com\/blog\/web-scraping-with-python.html\">\u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Python<\/a>, \u043f\u043e\u0447\u0438\u0442\u0430\u0439\u0442\u0435. \u0410 \u0437\u0434\u0435\u0441\u044c \u043c\u044b \u043e\u0431\u0441\u0443\u0434\u0438\u043c \u0440\u0430\u0437\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441 PHP \u0434\u043b\u044f \u0441\u043a\u0440\u0435\u0439\u043f\u0438\u043d\u0433\u0430 \u0432\u0435\u0431-\u0441\u0442\u0440\u0430\u043d\u0438\u0446: Guzzle, Goutte, Simple HTML DOM, Headless-\u0431\u0440\u0430\u0443\u0437\u0435\u0440 Symfony Panther. <br \/>  <a name=\"habracut\"><\/a><br \/>  \u0412\u043e\u0442 \u0447\u0442\u043e \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b:<\/p>\n<ul>\n<li>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e \u0432\u0435\u0440\u0441\u0438\u044e PHP.<\/li>\n<li>\u0421\u043a\u0430\u0447\u0430\u0439\u0442\u0435 <a href=\"https:\/\/getcomposer.org\/\">Composer<\/a> \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u0442\u0435 \u0435\u0433\u043e \u0434\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0440\u0430\u0437\u043d\u044b\u0445 PHP-\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0434\u043b\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0432\u0435\u0431-\u0441\u043a\u0440\u0435\u0439\u043f\u0438\u043d\u0433\u0430.<\/li>\n<li>\u0412\u044b\u0431\u0435\u0440\u0438\u0442\u0435 \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440 \u043f\u043e \u0432\u043a\u0443\u0441\u0443.<\/li>\n<\/ul>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0438 \u043f\u0435\u0440\u0435\u0439\u0434\u0438\u0442\u0435 \u0432 \u043d\u0435\u0451:<\/p>\n<pre><code class=\"php\">mkdir php_scraper cd php_scraper <\/code><\/pre>\n<p>  \u0412\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435 \u044d\u0442\u0438 \u0434\u0432\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0434\u043b\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 composer.json:<\/p>\n<pre><code class=\"php\">composer init \u2014 require=\u201dphp &gt;=7.4&quot; --no-interaction composer update <\/code><\/pre>\n<p>  \u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c.<\/p>\n<h2>1. \u0412\u0435\u0431-\u0441\u043a\u0440\u0435\u0439\u043f\u0438\u043d\u0433 \u043d\u0430 PHP \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Guzzle, XML \u0438 XPath<\/h2>\n<p>  <a href=\"http:\/\/docs.guzzlephp.org\/en\/stable\/\">Guzzle<\/a> \u2014 \u044d\u0442\u043e HTTP-\u043a\u043b\u0438\u0435\u043d\u0442 \u0434\u043b\u044f PHP, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u043b\u0435\u0433\u043a\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u044b. \u041e\u043d \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u043a \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. <a href=\"https:\/\/ru.wikipedia.org\/wiki\/XML\">XML<\/a> \u2014 \u044f\u0437\u044b\u043a \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0438 \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u0443\u0434\u043e\u0431\u043e\u0447\u0438\u0442\u0430\u0435\u043c\u043e\u043c \u0434\u043b\u044f \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430 \u0438 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430 \u0444\u043e\u0440\u043c\u0430\u0442\u0435. <a href=\"https:\/\/ru.wikipedia.org\/wiki\/XPath\">XPath<\/a> \u2014 \u044d\u0442\u043e \u044f\u0437\u044b\u043a \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0434\u043b\u044f \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u0438 \u0432\u044b\u0431\u043e\u0440\u0430 XML-\u0443\u0437\u043b\u043e\u0432. <\/p>\n<p>  \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u0441\u043a\u0440\u0435\u0439\u043f\u0438\u043d\u0433\u0430 \u0441\u0430\u0439\u0442\u0430. \u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 Guzzle \u0447\u0435\u0440\u0435\u0437 Composer, \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0443:<\/p>\n<pre><code class=\"php\">composer require guzzlehttp\/guzzle <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 Guzzle \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u044b\u0439 PHP-\u0444\u0430\u0439\u043b guzzle_requests.php, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043a\u043e\u0434. \u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0441\u043f\u0430\u0440\u0441\u0438\u043c \u0441\u0430\u0439\u0442 <a href=\"https:\/\/books.toscrape.com\/\">Books to Scrape<\/a>, \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u0430\u0439\u0442\u044b \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043a\u0440\u0435\u0439\u043f\u0438\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044f \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e. <i>Books to Scrape<\/i> \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/6fd\/91d\/27a\/6fd91d27ac8ce8364f8755f5cc178338.png\"><\/div>\n<p>  \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u043a\u043d\u0438\u0433 \u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u0438\u0445 \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435. \u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 HTML-\u043c\u0430\u043a\u0435\u0442\u0435. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u043b\u0438\u043a\u043d\u0443\u0432 \u043f\u0440\u0430\u0432\u043e\u0439 \u043a\u043d\u043e\u043f\u043a\u043e\u0439 \u043d\u0430\u0434 \u0441\u043f\u0438\u0441\u043a\u043e\u043c \u043a\u043d\u0438\u0433 \u0438 \u0432\u044b\u0431\u0440\u0430\u0432 \u043f\u0443\u043d\u043a\u0442 <i>Inspect<\/i>. \u0421\u043a\u0440\u0438\u043d\u0448\u043e\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/0cc\/937\/f3b\/0cc937f3b86d1fb6b22659eb1e1905d2.png\"><\/div>\n<p>  \u0412\u043d\u0443\u0442\u0440\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 <code>&lt;\u043el class=\u201dr\u043ew\u201d&gt;<\/code> \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0441\u043f\u0438\u0441\u043e\u043a. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u2014 <code>li<\/code>. \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u043d\u0438\u0433\u0438, \u043e\u043d\u043e \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0432\u043d\u0443\u0442\u0440\u0438 <code>\u0430<\/code>, \u0432\u043d\u0443\u0442\u0440\u0438 <code>h3<\/code>, \u0432\u043d\u0443\u0442\u0440\u0438 <code>article<\/code>, \u0438 \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u0432\u043d\u0443\u0442\u0440\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 <code>li<\/code>. \u0427\u0442\u043e\u0431\u044b \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c Guzzle, XML \u0438 Xpath \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0432 guzzle_requests.php \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"php\">&lt;?php#  scraping books to scrape: https:\/\/books.toscrape.com\/ require \u2018vendor\/autoload.php\u2019; $httpClient = new \\GuzzleHttp\\Client(); $response = $httpClient-&gt;get(\u2018https:\/\/books.toscrape.com\/'); $htmlString = (string) $response-&gt;getBody(); \/\/add this line to suppress any warnings libxml_use_internal_errors(true); $doc = new DOMDocument(); $doc-&gt;loadHTML($htmlString); $xpath = new DOMXPath($doc); <\/code><\/pre>\n<p>  \u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u0442 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u043e\u043a\u0438, \u0437\u0430\u0442\u0435\u043c \u043f\u0430\u0440\u0441\u0438\u0442 \u0435\u0451 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e XML \u0438 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <code>$xpath<\/code>. \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0442\u0435\u043a\u0441\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 \u0442\u0435\u0433\u0430 <code>a<\/code>. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u0444\u0430\u0439\u043b<\/p>\n<pre><code class=\"php\">$titles = $xpath-&gt;evaluate(\u2018\/\/ol[@class=&quot;row&quot;]\/\/li\/\/article\/\/h3\/a\u2019); $extractedTitles = []; foreach ($titles as $title) { $extractedTitles[] = $title-&gt;textContent.PHP_EOL; echo $title-&gt;textContent.PHP_EOL; } <\/code><\/pre>\n<p>  \u0412 \u044d\u0442\u043e\u043c \u043a\u043e\u0434\u0435 <code>\/\/ol[@class=&quot;row&quot;]<\/code> \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0432\u0435\u0441\u044c \u0441\u043f\u0438\u0441\u043e\u043a. \u0423 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0441\u043f\u0438\u0441\u043a\u0430 \u0435\u0441\u0442\u044c \u0442\u0435\u0433 <code>a<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u0434\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0439 \u043a\u043d\u0438\u0433. \u0422\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u0433 <code>h3<\/code> \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 <code>a<\/code>, \u044d\u0442\u043e \u043e\u0431\u043b\u0435\u0433\u0447\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u043d\u0438\u043c. \u0414\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0438 \u0435\u0451 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0446\u0438\u043a\u043b\u043e\u043c <code>foreach<\/code>. \u041d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u0438\u0437\u0432\u043b\u0435\u0447\u0451\u043d\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0442\u044c \u0438\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043c\u0430\u0441\u0441\u0438\u0432\u0430, \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u0444\u0430\u0439\u043b \u0438\u043b\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432 \u0411\u0414. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0444\u0430\u0439\u043b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e PHP \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435, \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0432 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u0443\u044e \u043d\u0438\u0436\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0443. <\/p>\n<pre><code class=\"php\">php guzzle_requests.php <\/code><\/pre>\n<p>  \u041d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u043f\u043e\u044f\u0432\u0438\u0442\u044c\u0441\u044f \u0432\u043e\u0442 \u0447\u0442\u043e:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/5fe\/063\/1ac\/5fe0631ac1a46b462060469114ac831e.png\"><\/div>\n<p>  \u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u0410 \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u043a\u043d\u0438\u0433?<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/eb9\/fd9\/127\/eb9fd91277328eacb59f9a65fa12a482.png\"><\/div>\n<p>  \u0426\u0435\u043d\u0430 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0442\u0435\u0433\u0435 <code>p<\/code> \u0432\u043d\u0443\u0442\u0440\u0438 \u0442\u0435\u0433\u0430 <code>div<\/code>. \u0412 \u043a\u043e\u0434\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u0433\u043e\u0432 <code>p<\/code> \u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e <code>div<\/code>. \u0427\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 \u043d\u0443\u0436\u043d\u044b\u0435, \u043c\u044b \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440\u0430\u043c\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 CSS, \u043a\u043e\u0442\u043e\u0440\u044b\u0435, \u043a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0435\u0433\u0430. \u0412\u043e\u0442 \u043a\u043e\u0434 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0442\u0435\u0433\u0430 \u0446\u0435\u043d \u0438 \u043a\u043e\u043d\u043a\u0430\u0442\u0435\u043d\u0430\u0446\u0438\u0438 \u0435\u0433\u043e \u0441\u043e \u0441\u0442\u0440\u043e\u043a\u043e\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430:<\/p>\n<pre><code class=\"php\">$titles = $xpath-&gt;evaluate(\u2018\/\/ol[@class=\u201drow\u201d]\/\/li\/\/article\/\/h3\/a\u2019); $prices = $xpath-&gt;evaluate(\u2018\/\/ol[@class=\u201drow\u201d]\/\/li\/\/article\/\/div[@class=\u201dproduct_price\u201d]\/\/p[@class=\u201dprice_color\u201d]\u2019); foreach ($titles as $key =&gt; $title) { echo $title-&gt;textContent . \u2018 @ \u2018. $prices[$key]-&gt;textContent.PHP_EOL; } <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043a\u043e\u0434 \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/5fd\/ef0\/dbd\/5fdef0dbdc199dca83d634d04355fa35.png\"><\/div>\n<p>  \u0412\u0430\u0448 \u043a\u043e\u0434 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"php\">&lt;?php # scraping books to scrape:https:\/\/books.toscrape.com\/ require \u2018vendor\/autoload.php\u2019; $httpClient = new \\GuzzleHttp\\Client(); $response = $httpClient-&gt;get(\u2018https:\/\/books.toscrape.com\/'); $htmlString = (string) $response-&gt;getBody(); \/\/add this line to suppress any warnings libxml_use_internal_errors(true); $doc = new DOMDocument(); $doc-&gt;loadHTML($htmlString); $xpath = new DOMXPath($doc); $titles = $xpath-&gt;evaluate(\u2018\/\/ol[@class=\u201drow\u201d]\/\/li\/\/article\/\/h3\/a\u2019); $prices = $xpath-&gt;evaluate(\u2018\/\/ol[@class=\u201drow\u201d]\/\/li\/\/article\/\/div[@class=\u201dproduct_price\u201d]\/\/p[@class=\u201dprice_color\u201d]\u2019); foreach ($titles as $key =&gt; $title) { echo $title-&gt;textContent . \u2018 @ \u2018. $prices[$key]-&gt;textContent.PHP_EOL; } <\/code><\/pre>\n<p>  \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u044d\u0442\u043e \u043b\u0438\u0448\u044c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0432\u0435\u0431-\u0441\u043a\u0440\u0435\u0439\u043f\u0435\u0440, \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c. \u041f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435.<\/p>\n<h2>2. \u0412\u0435\u0431-\u0441\u043a\u0440\u0435\u0439\u043f\u0438\u043d\u0433 \u043d\u0430 PHP \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Goutte<\/h2>\n<p>  <a href=\"https:\/\/github.com\/FriendsOfPHP\/Goutte\">Goutte<\/a> \u2014 \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u044b\u0439 HTTP-\u043a\u043b\u0438\u0435\u043d\u0442 \u0434\u043b\u044f PHP, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0432\u0435\u0431-\u0441\u043a\u0440\u0435\u0439\u043f\u0438\u043d\u0433\u0430. \u0415\u0433\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0430\u0432\u0442\u043e\u0440 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 <a href=\"https:\/\/symfony.com\/\">Symfony<\/a>, \u043e\u043d \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0445\u043e\u0440\u043e\u0448\u0438\u0439 API \u0434\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 HTML\/XML-\u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u0441\u0430\u0439\u0442\u043e\u0432. \u0412\u043e\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0434\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u0439 \u0441\u043a\u0440\u0435\u0439\u043f\u0438\u043d\u0433\u0430:<\/p>\n<ul>\n<li><a href=\"https:\/\/symfony.com\/doc\/current\/components\/browser_kit.html\">BrowserKit<\/a> \u0434\u043b\u044f \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0438 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430.<\/li>\n<li><a href=\"https:\/\/symfony.com\/doc\/current\/components\/css_selector.html\">CssSelector<\/a> \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 CSS-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 XPath-\u0437\u0430\u043f\u0440\u043e\u0441\u044b.<\/li>\n<li><a href=\"https:\/\/symfony.com\/doc\/current\/components\/dom_crawler.html\">DomCrawler<\/a> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c DOMDocument \u0438 XPath.<\/li>\n<li><a href=\"https:\/\/symfony.com\/doc\/current\/http_client.html\">Symfony HTTP-\u043a\u043b\u0438\u0435\u043d\u0442<\/a> \u2014 \u043d\u043e\u0432\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043e\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u044b Symfony.<\/li>\n<\/ul>\n<p>  \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c Goutte \u0447\u0435\u0440\u0435\u0437 \u0421omposer, \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0432 \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435:<\/p>\n<pre><code class=\"php\">composer require fabpot\/goutte <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u0444\u0430\u0439\u043b goutte_requests.php \u0434\u043b\u044f \u043a\u043e\u0434\u0430. \u041d\u0438\u0436\u0435 \u043c\u044b \u043e\u0431\u0441\u0443\u0434\u0438\u043c, \u0447\u0442\u043e \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Guzzle \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0433\u043b\u0430\u0432\u0435. \u0418\u0437\u0432\u043b\u0435\u0447\u0451\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Goutte \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u043a\u043d\u0438\u0433 \u0441 \u0441\u0430\u0439\u0442\u0430 <a href=\"https:\/\/books.toscrape.com\/\">Books to Scrape<\/a>. \u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u043a\u0430\u0436\u0435\u043c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0446\u0435\u043d\u044b \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0451 \u0432 \u043a\u043e\u0434\u0435. \u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0432 \u0444\u0430\u0439\u043b goutte_requests.php \u044d\u0442\u043e\u0442 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"php\">&lt;?php # scraping books to scrape:https:\/\/books.toscrape.com\/ require \u2018vendor\/autoload.php\u2019; $httpClient = new \\Goutte\\Client(); $response = $httpClient-&gt;request(\u2018GET\u2019, \u2018https:\/\/books.toscrape.com\/'); $titles = $response-&gt;evaluate(\u2018\/\/ol[@class=\u201drow\u201d]\/\/li\/\/article\/\/h3\/a\u2019); $prices = $response-&gt;evaluate(\u2018\/\/ol[@class=\u201drow\u201d]\/\/li\/\/article\/\/div[@class=\u201dproduct_price\u201d]\/\/p[@class=\u201dprice_color\u201d]\u2019); \/\/ we can store the prices into an array $priceArray = []; foreach ($prices as $key =&gt; $price) { $priceArray[] = $price-&gt;textContent; } \/\/ we extract the titles and display to the terminal together with the prices foreach ($titles as $key =&gt; $title) { echo $title-&gt;textContent . \u2018 @ \u2018. $priceArray[$key] . PHP_EOL; } <\/code><\/pre>\n<p>  \u0412\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u0435\u0433\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435:<\/p>\n<pre><code class=\"php\"> php goutte_requests.php <\/code><\/pre>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/d88\/7f4\/6ec\/d887f46ecc87a74084975ced613f27d7.png\"><\/div>\n<p>  \u0412\u044b\u0448\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043d \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0441\u043a\u0440\u0435\u0439\u043f\u0438\u043d\u0433\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Goutte. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431 \u0441 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 CSSSelector \u0438\u0437 Goutte. CSS-\u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440 \u043f\u0440\u043e\u0449\u0435 \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438, \u0447\u0435\u043c XPath \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0430. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0435\u0449\u0451 \u043e\u0434\u0438\u043d PHP \u0444\u0430\u0439\u043b \u2014 goutte_css_requests.php. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043d\u0435\u0433\u043e \u043a\u043e\u0434:<\/p>\n<pre><code class=\"php\">&lt;?php # scraping books to scrape:https:\/\/books.toscrape.com\/ require \u2018vendor\/autoload.php\u2019; $httpClient = new \\Goutte\\Client(); $response = $httpClient-&gt;request(\u2018GET\u2019, \u2018https:\/\/books.toscrape.com\/'); \/\/ get prices into an array $prices = []; $response-&gt;filter(\u2018.row li article div.product_price p.price_color\u2019)-&gt;each(function ($node) use (&amp;$prices) { $prices[] = $node-&gt;text(); }); \/\/ echo titles and prices $priceIndex = 0; $response-&gt;filter(\u2018.row li article h3 a\u2019)-&gt;each(function ($node) use ($prices, &amp;$priceIndex) { echo $node-&gt;text() . \u2018 @ \u2018 . $prices[$priceIndex] .PHP_EOL; $priceIndex++; }); <\/code><\/pre>\n<p>  CSSSelector \u0441\u0434\u0435\u043b\u0430\u043b \u043a\u043e\u0434 \u0447\u0438\u0449\u0435 \u0438 \u0443\u0434\u043e\u0431\u043e\u0447\u0438\u0442\u0430\u0435\u043c\u0435\u0435. \u0412\u044b \u043c\u043e\u0433\u043b\u0438 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>&amp;<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0443 \u0432 \u0446\u0438\u043a\u043b <code>\u00abeach\u00bb<\/code> \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, \u0430 \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0435\u0451 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0415\u0441\u043b\u0438 \u0446\u0438\u043a\u043b \u043c\u0435\u043d\u044f\u0435\u0442 <code>&amp;$prices<\/code>, \u0442\u043e \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u043c\u0438 \u0446\u0438\u043a\u043b\u0430 \u0442\u043e\u0436\u0435 \u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e <a href=\"https:\/\/www.php.net\/manual\/en\/language.references.whatdo.php\">\u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u0438\u0438 \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0430\u043c<\/a> \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 PHP. \u0412\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u0444\u0430\u0439\u043b \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435:<\/p>\n<pre><code class=\"php\">php goutte_css_requests.php <\/code><\/pre>\n<p>  \u0418 \u0443\u0432\u0438\u0434\u0438\u043c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/179\/0ed\/45a\/1790ed45a0476ed198e05784cab34d8d.png\"><\/div>\n<p>  \u041d\u0430\u0448 \u0432\u0435\u0431-\u0441\u043a\u0440\u0435\u0439\u043f\u0435\u0440 \u0441 Goutte \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0445\u043e\u0440\u043e\u0448\u043e. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u043a\u043b\u0438\u043a\u043d\u0443\u0442\u044c \u043d\u0430 \u0441\u0441\u044b\u043b\u043a\u0443 \u0438 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043d\u0430 \u0434\u0440\u0443\u0433\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443. \u041d\u0430 \u043d\u0430\u0448\u0435\u043c \u0434\u0435\u043c\u043e-\u0441\u0430\u0439\u0442\u0435 <a href=\"https:\/\/books.toscrape.com\/\">Books to Scrape<\/a> \u043f\u0440\u0438 \u043a\u043b\u0438\u043a\u0435 \u043d\u0430 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u043d\u0438\u0433\u0438 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u0441 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/042\/ad9\/9ca\/042ad99cabe08b871d491fa68beb2677.png\"><\/div>\n<p>  \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u043a\u043b\u0438\u043a\u043d\u0443\u0442\u044c \u043d\u0430 \u0441\u0441\u044b\u043b\u043a\u0443 \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u043a\u043d\u0438\u0433, \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0441 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c \u0438 \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0435\u0433\u043e. \u0418\u0437\u0443\u0447\u0438\u043c \u043a\u043e\u0434 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/5ff\/953\/ab7\/5ff953ab7cab95e8053f12b1cbb16122.png\"><\/div>\n<p>  \u041d\u0430\u0448 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u043f\u0443\u0442\u044c \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a\u0438\u043c: \u044d\u043b\u0435\u043c\u0435\u043d\u0442 <code>div cl\u0430ss=&quot;content&quot;<\/code>, \u0437\u0430\u0442\u0435\u043c <code>div id=&quot;content_inner&quot;<\/code>, \u0437\u0430\u0442\u0435\u043c \u043e\u0434\u0438\u043d \u0442\u0435\u0433 <code>article<\/code>, \u0438 \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u0442\u0435\u0433 <code>p<\/code>. \u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u0433\u043e\u0432 <code>p<\/code>, \u0442\u0435\u0433 \u0441 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0435\u0442\u0432\u0451\u0440\u0442\u044b\u043c \u0432\u043d\u0443\u0442\u0440\u0438 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 <code>div class=&quot;content&quot;<\/code>. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u0430\u0441\u0441\u0438\u0432\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442\u0441\u044f \u0441 0, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043d\u043e\u0434\u0443 \u0432 \u0442\u0440\u0435\u0442\u044c\u0435\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u0435. \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043a\u043e\u0434. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u043e\u0431\u0430\u0432\u0438\u043c Composer-\u043f\u0430\u043a\u0435\u0442 \u0434\u043b\u044f \u043e\u0431\u043b\u0435\u0433\u0447\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 HTML5:<\/p>\n<pre><code class=\"php\">composer require masterminds\/html5 <\/code><\/pre>\n<p>  \u041c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u043c \u0444\u0430\u0439\u043b goutte_css_requests.php:<\/p>\n<pre><code class=\"php\">&lt;?php # scraping books to scrape:https:\/\/books.toscrape.com\/ require \u2018vendor\/autoload.php\u2019; $httpClient = new \\Goutte\\Client(); $response = $httpClient-&gt;request(\u2018GET\u2019, \u2018https:\/\/books.toscrape.com\/'); \/\/ get prices into an array $prices = []; $response-&gt;filter(\u2018.row li article div.product_price p.price_color\u2019) -&gt;each(function ($node) use (&amp;$prices) { $prices[] = $node-&gt;text(); }); \/\/ echo title, price, and description $priceIndex = 0; $response-&gt;filter(\u2018.row li article h3 a\u2019) -&gt;each(function ($node) use ($prices, &amp;$priceIndex, $httpClient) { $title = $node-&gt;text(); $price = $prices[$priceIndex]; \/\/getting the description $description = $httpClient-&gt;click($node-&gt;link()) -&gt;filter(\u2018.content #content_inner article p\u2019)-&gt;eq(3)-&gt;text(); \/\/ display the result echo \u201c{$title} @ {$price} : {$description}\\n\\n\u201d; $priceIndex++; }); <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0435\u0433\u043e \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435, \u0442\u043e \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435, \u0446\u0435\u043d\u0443 \u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u043d\u0438\u0433\u0438:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/426\/5e5\/400\/4265e5400dbd51da8b17c618af115e4e.png\"><\/div>\n<p>  \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 Goutte CSS Selector \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043a\u043b\u0438\u043a\u0430\u0442\u044c \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043b\u0435\u0433\u043a\u043e \u0431\u0440\u043e\u0434\u0438\u0442\u044c \u043f\u043e \u043c\u043d\u043e\u0433\u043e\u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043d\u044b\u043c \u0441\u0430\u0439\u0442\u0430\u043c \u0438 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u044c \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0433\u043e\u0434\u043d\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438.<\/p>\n<h2>3. \u0412\u0435\u0431-\u0441\u043a\u0440\u0435\u0439\u043f\u0438\u043d\u0433 \u043d\u0430 PHP \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Simple HTML DOM<\/h2>\n<p>  <a href=\"https:\/\/simplehtmldom.sourceforge.io\/manual.htm#section_quickstart\">Simple HTML DOM<\/a> \u2014 \u0435\u0449\u0451 \u043e\u0434\u043d\u0430 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u0438\u0441\u0442\u0438\u0447\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0432\u0435\u0431-\u0441\u043a\u0440\u0435\u0439\u043f\u0438\u043d\u0433\u0430 \u0434\u043b\u044f PHP. \u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0431\u0443\u0434\u0435\u043c \u0441 \u0442\u043e\u0433\u043e \u0436\u0435 \u0441\u0430\u0439\u0442\u0430. \u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u043f\u0430\u043a\u0435\u0442, \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u0444\u0430\u0439\u043b composer.json \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u0438\u0436\u0435\u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u0431\u043b\u043e\u043a\u0430 <code>require:{}<\/code>, \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043e\u043a \u0432\u0435\u0440\u0441\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"php\">\u201cminimum-stability\u201d: \u201cdev\u201d, \u201cprefer-stable\u201d: true <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443:<\/p>\n<pre><code class=\"php\">composer require simplehtmldom\/simplehtmldom <\/code><\/pre>\n<p>  \u0417\u0430\u0442\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043d\u043e\u0432\u044b\u0439 PHP-\u0444\u0430\u0439\u043b \u2014 simplehtmldom_requests.php. \u041c\u044b \u0443\u0436\u0435 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u043b\u0438 \u043c\u0430\u043a\u0435\u0442 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b, \u0442\u0430\u043a \u0447\u0442\u043e \u0441\u0440\u0430\u0437\u0443 \u043f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u043a \u043a\u043e\u0434\u0443. \u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0432 simplehtmldom_requests.php:<\/p>\n<pre><code class=\"php\">&lt;?php # scraping books to scrape:https:\/\/books.toscrape.com\/ require \u2018vendor\/autoload.php\u2019; $httpClient = new \\simplehtmldom\\HtmlWeb(); $response = $httpClient-&gt;load(\u2018https:\/\/books.toscrape.com\/'); \/\/ echo the title echo $response-&gt;find(\u2018title\u2019, 0)-&gt;plaintext . PHP_EOL . PHP_EOL; \/\/ get the prices into an array $prices = []; foreach ($response-&gt;find(\u2018.row li article div.product_price p.price_color\u2019) as $price) { $prices[] = $price-&gt;plaintext; } \/\/ echo titles and prices foreach ($response-&gt;find(\u2018.row li article h3 a\u2019) as $key =&gt; $title) { echo \u201c{$title-&gt;plaintext} @ {$prices[$key]} \\n\u201d; } <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043a\u043e\u0434 \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435, \u043f\u043e\u043b\u0443\u0447\u0438\u043c:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/21f\/4ec\/c68\/21f4ecc68957687889cc58de324ce80c.png\"><\/div>\n<p>  \u0411\u043e\u043b\u044c\u0448\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0441\u043a\u0440\u0435\u0439\u043f\u0438\u043d\u0433\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/simplehtmldom.sourceforge.io\/manual_api.htm\">Simple HTML DOM \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043f\u043e API<\/a>.<\/p>\n<h2>4. \u0412\u0435\u0431-\u0441\u043a\u0440\u0435\u0439\u043f\u0438\u043d\u0433 \u043d\u0430 PHP \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Headless-\u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430 Symfony Panther<\/h2>\n<p>  Headless-\u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u2014 \u044d\u0442\u043e \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u0431\u0435\u0437 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u044d\u0442\u043e\u0439 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u0432 \u0441\u0440\u0435\u0434\u0435, \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e\u0439 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0443 \u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434 \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0435\u0439, \u043a\u0430\u043a \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445. \u0417\u0430\u0447\u0435\u043c \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e? \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0434\u043b\u044f \u0440\u0430\u0437\u0432\u0451\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u044f \u0432\u0435\u0431-\u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0438 \u043d\u0430 JavaScript. \u042d\u0442\u0438 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043e\u0432 HTML-\u043a\u043e\u0434. \u0412 \u0434\u0440\u0443\u0433\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0434\u043b\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442 AJAX. \u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u044b\u0435 HTML-\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441\u043a\u0440\u0435\u0439\u043f\u0438\u043d\u0433\u0430 \u0431\u044b\u043b \u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u043d\u043d\u044b\u043c. \u0410 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430\u043c\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 HTML \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e JavaScript \u0438 AJAX, \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0435\u0435\u0441\u044f DOM-\u0434\u0435\u0440\u0435\u0432\u043e \u043c\u043e\u0436\u0435\u0442 \u0441\u0438\u043b\u044c\u043d\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043d\u0430\u0440\u0443\u0448\u0438\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441\u043a\u0440\u0435\u0439\u043f\u0435\u0440\u0430. \u0420\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 headless-\u0431\u0440\u0430\u0443\u0437\u0435\u0440.<\/p>\n<p>  \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0442\u0430\u043a\u043e\u0433\u043e \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c PHP-\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <a href=\"https:\/\/github.com\/symfony\/panther\">Symfony Panther<\/a>. \u0415\u0451 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442 \u0438 \u0434\u043b\u044f \u0441\u043a\u0440\u0435\u0439\u043f\u0438\u043d\u0433\u0430, \u0438 \u0434\u043b\u044f \u043f\u0440\u043e\u0433\u043e\u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0445 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043e\u0432. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0442\u0430\u043a\u0438\u0435 \u0436\u0435 \u043c\u0435\u0442\u043e\u0434\u044b, \u043a\u0430\u043a \u0438 Goutte, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Panther \u0432\u043c\u0435\u0441\u0442\u043e Goutte. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 Panther:<\/p>\n<ul>\n<li>\u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u0442 JavaScript \u0432 \u0432\u0435\u0431-\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430\u0445;<\/li>\n<li>\u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u043e\u0435 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043d\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435;<\/li>\n<li>\u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u043a\u043e\u0434\u0430;<\/li>\n<li>\u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0432\u0441\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 Chrome \u0438 Firefox;<\/li>\n<li>\u043c\u043e\u0436\u0435\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043d\u0448\u043e\u0442\u044b;<\/li>\n<li>\u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 JS-\u043a\u043e\u0434 \u0438\u043b\u0438 XPath-\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b.<\/li>\n<\/ul>\n<p>  \u041c\u044b \u0443\u0436\u0435 \u043c\u043d\u043e\u0433\u043e \u0441\u043a\u0440\u0435\u0439\u043f\u0438\u043b\u0438, \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043a\u043e\u0435-\u0447\u0442\u043e \u0434\u0440\u0443\u0433\u043e\u0435. \u0411\u0443\u0434\u0435\u043c \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c HTML-\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0438 \u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0451 \u0441\u043a\u0440\u0438\u0448\u043e\u0442. \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c <a href=\"https:\/\/github.com\/symfony\/panther\">Symfony Panther<\/a>:<\/p>\n<pre><code class=\"php\">composer require symfony\/panther <\/code><\/pre>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u044b\u0439 PHP-\u0444\u0430\u0439\u043b panther_requests.php. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043d\u0435\u0433\u043e \u043a\u043e\u0434:<\/p>\n<pre><code class=\"php\">&lt;?php # scraping books to scrape:https:\/\/books.toscrape.com\/ require \u2018vendor\/autoload.php\u2019; $httpClient = \\Symfony\\Component\\Panther\\Client::createChromeClient(); \/\/ for a Firefox client use the line below instead \/\/$httpClient = \\Symfony\\Component\\Panther\\Client::createFirefoxClient(); \/\/ get response $response = $httpClient-&gt;get(\u2018https:\/\/books.toscrape.com\/'); \/\/ take screenshot and store in current directory $response-&gt;takeScreenshot($saveAs = \u2018books_scrape_homepage.jpg\u2019); \/\/ let\u2019s display some book titles $response-&gt;getCrawler()-&gt;filter(\u2018.row li article h3 a\u2019) -&gt;each(function ($node) { echo $node-&gt;text() . PHP_EOL; }); <\/code><\/pre>\n<p>  \u0427\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0435\u0433\u043e \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435, \u043d\u0443\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u044b \u0434\u043b\u044f Chrome \u0438\u043b\u0438 Firefox, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u043e\u0433\u043e \u0432 \u0432\u0430\u0448\u0435\u043c \u043a\u043e\u0434\u0435. \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, Composer \u043c\u043e\u0436\u0435\u0442 \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438. \u0412\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u043e\u0432:<\/p>\n<pre><code class=\"php\">composer require --dev dbrekelmans\/bdi &amp;&amp; vendor\/bin\/bdi detect drivers <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435 PHP-\u0444\u0430\u0439\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u0441\u043a\u0440\u0438\u043d\u0448\u043e\u0442 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442 \u0435\u0433\u043e \u0432 \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e, \u0430 \u043f\u043e\u0442\u043e\u043c \u043f\u043e\u043a\u0430\u0436\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0439 \u043a\u043d\u0438\u0433 \u0441\u043e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/64f\/0e3\/c35\/64f0e3c35cc70878e2c447999b6a57ab.png\"><\/div>\n<p>  <\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>  \u041c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u0440\u0430\u0437\u043d\u044b\u0435 open-source PHP-\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0441\u043a\u0440\u0435\u0439\u043f\u0438\u043d\u0433\u0430 \u0441\u0430\u0439\u0442\u043e\u0432. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044d\u0442\u043e\u0433\u043e \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430 \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u0438\u0439 \u0441\u043a\u0440\u0435\u0439\u043f\u0435\u0440 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0439-\u0434\u0432\u0443\u0445 \u0441\u0442\u0440\u0430\u043d\u0438\u0446. \u0425\u043e\u0442\u044f \u043c\u044b \u043f\u0440\u043e\u0448\u043b\u0438\u0441\u044c \u043b\u0438\u0448\u044c \u043f\u043e \u0432\u0435\u0440\u0445\u0430\u043c, \u043d\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a. \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u0441\u043a\u0440\u0435\u0439\u043f\u0435\u0440, \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u044b\u0439 \u043e\u0431\u0445\u043e\u0434\u0438\u0442\u044c \u0442\u044b\u0441\u044f\u0447\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446. \u041a\u043e\u0434 \u0438\u0437 \u0441\u0442\u0430\u0442\u044c\u0438 \u043b\u0435\u0436\u0438\u0442 \u0432 <a href=\"https:\/\/github.com\/jaymoh\/php_web_scraper\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438<\/a>. <\/p>\n<p>  \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0432\u0430\u043c \u043f\u043e\u043b\u0435\u0437\u043d\u044b<\/p>\n<ul>\n<li><a href=\"https:\/\/www.scrapingdog.com\/blog\/best-datacenter-proxy-provider-webscraping\">Datacenter Proxies<\/a><\/li>\n<li><a href=\"https:\/\/www.scrapingdog.com\/blog\/web-scraping-101-with-java.html\">\u0412\u0435\u0431-\u0441\u043a\u0440\u0435\u0439\u043f\u0438\u043d\u0433 \u043d\u0430 Java<\/a><\/li>\n<li><a href=\"https:\/\/www.scrapingdog.com\/blog\/web-scraping-with-python.html\">\u0412\u0435\u0431-\u0441\u043a\u0440\u0435\u0439\u043f\u0438\u043d\u0433 \u043d\u0430 Python<\/a><\/li>\n<li><a href=\"https:\/\/www.scrapingdog.com\/blog\/web-scraping-101-with-nodejs.html\">\u0412\u0435\u0431-\u0441\u043a\u0440\u0435\u0439\u043f\u0438\u043d\u0433 \u043d\u0430 Nodejs<\/a><\/li>\n<li><a href=\"https:\/\/www.scrapingdog.com\/blog\/starting-with-selenium-python.html\">\u0412\u0435\u0431-\u0441\u043a\u0440\u0435\u0439\u043f\u0438\u043d\u0433 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Selenium \u0438 Python<\/a><\/li>\n<\/ul>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/mailru\/blog\/565028\/\"> https:\/\/habr.com\/ru\/company\/mailru\/blog\/565028\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/1e\/ns\/9s\/1ens9snce7hfihupglqn8956c3i.jpeg\" width=\"350\"><\/div>\n<p>  \u0422\u0435\u0440\u043c\u0438\u043d <i>web scraping<\/i> \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0438\u0437 \u0432\u0435\u0431-\u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435. \u0415\u0433\u043e \u0435\u0449\u0451 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 <i>web crawling<\/i> \u0438\u043b\u0438 <i>web data extraction<\/i>.<\/p>\n<p>  PHP \u0448\u0438\u0440\u043e\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0433\u043e \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0441\u0430\u0439\u0442\u043e\u0432 \u0438 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439. \u0418 \u043d\u0430 \u043d\u0451\u043c \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0435\u0431-\u0441\u043a\u0440\u0435\u0439\u043f\u0435\u0440. \u041d\u043e \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u043d\u0435 \u0445\u043e\u0442\u0438\u043c \u0438\u0437\u043e\u0431\u0440\u0435\u0442\u0430\u0442\u044c \u043a\u043e\u043b\u0435\u0441\u043e, \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0433\u043e\u0442\u043e\u0432\u044b\u043c\u0438 open-source \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c\u0438 \u0434\u043b\u044f \u0432\u0435\u0431-\u0441\u043a\u0440\u0435\u0439\u043f\u0438\u043d\u0433\u0430. \u041a\u0441\u0442\u0430\u0442\u0438, \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u043e\u0442\u043b\u0438\u0447\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e \u043f\u0440\u043e <a href=\"https:\/\/www.scrapingdog.com\/blog\/web-scraping-101-with-nodejs.html\">\u0432\u0435\u0431-\u0441\u043a\u0440\u0435\u0439\u043f\u0438\u043d\u0433 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Node.js<\/a> \u0438 <a href=\"https:\/\/www.scrapingdog.com\/blog\/web-scraping-with-python.html\">\u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Python<\/a>, \u043f\u043e\u0447\u0438\u0442\u0430\u0439\u0442\u0435. \u0410 \u0437\u0434\u0435\u0441\u044c \u043c\u044b \u043e\u0431\u0441\u0443\u0434\u0438\u043c \u0440\u0430\u0437\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441 PHP \u0434\u043b\u044f \u0441\u043a\u0440\u0435\u0439\u043f\u0438\u043d\u0433\u0430 \u0432\u0435\u0431-\u0441\u0442\u0440\u0430\u043d\u0438\u0446: Guzzle, Goutte, Simple HTML DOM, Headless-\u0431\u0440\u0430\u0443\u0437\u0435\u0440 Symfony Panther.   <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-325610","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/325610","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=325610"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/325610\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=325610"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=325610"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=325610"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}