{"id":264613,"date":"2015-08-31T11:43:02","date_gmt":"2015-08-31T07:43:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=264613"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=264613","title":{"rendered":"\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0432\u0441\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0441\u0430\u0439\u0442\u0430 \u0432 \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440\u0435 html"},"content":{"rendered":"<p>     \t<img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/972\/8e0\/b09\/9728e0b09d794a6793fa71d53cf6bf1a.jpg\"\/>  <\/p>\n<h4>\u0418\u043d\u0442\u0440\u043e<\/h4>\n<p>  \u0426\u0435\u043b\u044c \u2014 \u0441\u043e\u0437\u0434\u0430\u0442\u044c <s>\u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434<\/s> \u0441\u043a\u0440\u0438\u043f\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0431\u0435\u0436\u0438\u0442\u0441\u044f \u043f\u043e \u0441\u0430\u0439\u0442\u0443 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442 \u043a\u0430\u0436\u0434\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0441\u0430\u0439\u0442\u0430 \u043d\u0430 \u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0441\u0442\u044c html. <br \/>  \u042f \u0441\u043b\u044b\u0448\u0430\u043b, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043d\u0430\u043f\u0430\u0434\u0430\u0435\u0442 \u043f\u0435\u0440\u0444\u0435\u043a\u0446\u0438\u043e\u043d\u0438\u0437\u043c, \u0442\u043e \u043d\u0430\u0434\u043e \u043f\u043e\u043b\u0435\u0436\u0430\u0442\u044c, \u043e\u0442\u0434\u043e\u0445\u043d\u0443\u0442\u044c \u0438 \u044d\u0442\u043e \u043f\u0440\u043e\u0439\u0434\u0435\u0442. <br \/>  \u041f\u043e\u0434\u0443\u043c\u0430\u0435\u0448\u044c, \u0432 \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440\u0435 \u043e\u0448\u0438\u0431\u043a\u0430\u2026<br \/>  \u041d\u043e \u0435\u0441\u043b\u0438 \u0432\u0441\u0435 \u0436\u0435 \u043d\u0435 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442, \u0442\u043e <a name=\"habracut\"><\/a><\/p>\n<h2>\u0421\u0442\u0430\u0432\u0438\u043c \u0434\u043e\u043a\u0435\u0440 \u0438 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0441 \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440\u043e\u043c<\/h2>\n<p>  \u0420\u0430\u043d\u044c\u0448\u0435 \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440 <a href=\"https:\/\/github.com\/tlvince\/w3c-validator-guide\">\u0431\u044b\u043b\u043e \u0434\u0435\u043b\u043e\u043c \u043c\u0443\u0442\u043e\u0440\u043d\u044b\u043c<\/a>. <br \/>  \u041d\u0435 \u0442\u043e, \u0447\u0442\u043e \u0431\u044b \u0441\u043b\u043e\u0436\u043d\u044b\u043c, \u0430 \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438. <br \/>  \u0421 \u043f\u0440\u0438\u0445\u043e\u0434\u043e\u043c \u0434\u043e\u043a\u0435\u0440\u0430 \u043e\u043d \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0437\u0430 \u0441\u0435\u043a\u0443\u043d\u0434\u044b. <br \/>  \u0421\u0442\u0430\u0432\u0438\u043c \u0434\u043e\u043a\u0435\u0440:  <\/p>\n<pre><code class=\"bash\">yum install docker <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0434\u043e\u043a\u0435\u0440\u0430 \u0431\u0435\u0440\u0435\u043c \u0441\u0435\u0431\u0435 \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u043e\u0431\u0440\u0430\u0437 <a href=\"https:\/\/hub.docker.com\/r\/magnetikonline\/html5validator\/\">\u0441 \u0441\u043e\u0431\u0440\u0430\u043d\u043d\u044b\u043c \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440\u043e\u043c<\/a>:  <\/p>\n<pre><code class=\"bash\">docker pull magnetikonline\/html5validator <\/code><\/pre>\n<p>  \u041a\u043e\u0433\u0434\u0430 \u043e\u0431\u0440\u0430\u0437 \u0437\u0430\u043a\u0430\u0447\u0430\u0435\u0442\u0441\u044f, \u0442\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0435\u0433\u043e:  <\/p>\n<pre><code class=\"bash\">docker run -p 8080:80 -p 8888:8888 --name validator --restart=always  -d magnetikonline\/html5validator <\/code><\/pre>\n<p>  \u0418 \u0441\u0442\u0430\u0440\u0442\u0443\u0435\u043c:  <\/p>\n<pre><code class=\"bash\">docker start validator <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0439\u0442\u0438 \u043d\u0430 <a href=\"http:\/\/localhost:8888\">http:\/\/localhost:8888<\/a> \u0438 \u0443\u0432\u0438\u0434\u0435\u0442\u044c:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/2ec\/2f0\/149\/2ec2f014994a4d4cad2284f808a35680.png\"\/><\/p>\n<p>  \u041b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442! \u0415\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0442\u0440\u0430\u0432\u0438\u0442\u044c \u043d\u0430 \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u0441\u0430\u0439\u0442. <br \/>  \u0418 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0441 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438:<\/p>\n<pre><code class=\"bash\">curl 'localhost:8888?doc=http:\/\/www.w3schools.com' <\/code><\/pre>\n<p>  <\/p>\n<h4>\u0418 \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/h4>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/af0\/438\/467\/af043846700d4d458c15fa937aef24cb.png\"\/><\/p>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440 \u043d\u0430\u0448\u0435\u043b 3 \u043e\u0448\u0438\u0431\u043a\u0438. <\/p>\n<h2>\u041f\u0430\u0443\u0447\u043e\u043a<\/h2>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/607\/ee0\/17d\/607ee017da0842fc8e0035374ccbb005.jpg\"\/><br \/>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0434\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b \u043e\u0431\u043e\u0448\u0435\u043b \u0432\u0441\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0441\u0430\u0439\u0442\u0430. <br \/>  \u0417\u0430 \u043e\u0441\u043d\u043e\u0432\u0443 \u044f \u0432\u0437\u044f\u043b \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 <a href=\"https:\/\/gist.github.com\/creaktive\/4347600\">web crawler\/scraper<\/a> \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 Mojo.<br \/>  \u0418 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b:<\/p>\n<pre><code class=\"perl\">#!\/usr\/bin\/env perl use 5.010; use open qw(:locale); use strict; use utf8; use warnings qw(all); use Mojo::UserAgent; use List::MoreUtils 'true'; use Term::ANSIColor;  # \u0410\u0434\u0440\u0435\u0441 \u0441\u0430\u0439\u0442\u0430 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 my $site_to_check = 'http:\/\/habrahabr.ru';  # \u0410\u0434\u0440\u0435\u0441 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440\u0430 my $local_validator = 'http:\/\/192.168.1.217:8888';  # FIFO queue my @urls = ( Mojo::URL-&gt;new($site_to_check) );  # User agent following up to 5 redirects my $ua = Mojo::UserAgent-&gt;new( max_redirects =&gt; 5 );  # Track accessed URLs my $active = 0; my %uniq;  sub parse {     my ($tx) = @_;      # Request URL     my $url = $tx-&gt;req-&gt;url;      # Extract and enqueue URLs     for my $e ( $tx-&gt;res-&gt;dom('a[href]')-&gt;each ) {          # Validate href attribute         my $link = Mojo::URL-&gt;new( $e-&gt;{href} );         next if 'Mojo::URL' ne ref $link;          # &quot;normalize&quot; link         $link = $link-&gt;to_abs( $tx-&gt;req-&gt;url )-&gt;fragment(undef);         next unless $link-&gt;protocol =~ \/^https?$\/x;          # Don't go deeper than \/a\/b\/c         next if @{ $link-&gt;path-&gt;parts } &gt; 3;          # Access every link only once         next if ++$uniq{ $link-&gt;to_string } &gt; 1;          # Don't visit other hosts         next if $link-&gt;host ne $url-&gt;host;          push @urls, $link;         my $get   = $ua-&gt;get( $local_validator . &quot;?doc=$link&quot; )-&gt;res-&gt;body;         my @answ  = split \/ \/, $get;         my $count = true { \/class=&quot;error&quot;\/ } @answ;         print color(&quot;green&quot;), $link, color(&quot;reset&quot;);         print &quot;  \u041a\u043e\u043b-\u0432\u043e \u043e\u0448\u0438\u0431\u043e\u043a \u0432 \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440\u0435: &quot;,           color(&quot;red&quot;), &quot;$count \\n&quot;, color(&quot;reset&quot;);      }      return; }  sub get_callback {     my ( undef, $tx ) = @_;      # Parse only OK HTML responses     $tx-&gt;res-&gt;code == 200       and $tx-&gt;res-&gt;headers-&gt;content_type =~ m{^text\/html\\b}ix       and parse($tx);      # Deactivate     --$active;      return; }  Mojo::IOLoop-&gt;recurring(     0 =&gt; sub {          # Keep up to 4 parallel crawlers sharing the same user agent         for ( $active .. 4 - 1 ) {              # Dequeue or halt if there are no active crawlers anymore             return ( $active or Mojo::IOLoop-&gt;stop )               unless my $url = shift @urls;              # Fetch non-blocking just by adding             # a callback and marking as active             ++$active;             $ua-&gt;get( $url =&gt; \\&get_callback );         }     } );  # Start event loop if necessary Mojo::IOLoop-&gt;start unless Mojo::IOLoop-&gt;is_running; <\/code><\/pre>\n<p>  <a href=\"https:\/\/github.com\/Alexmod\/crawler-validator\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0433\u0438\u0442\u0445\u0430\u0431<\/a>  <\/p>\n<h4>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b:<\/h4>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/03d\/190\/ede\/03d190ede1c74357be5377e7524cda62.png\"\/>     \t<\/p>\n<div class=\"clear\"><\/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=\"http:\/\/habrahabr.ru\/post\/265709\/\"> http:\/\/habrahabr.ru\/post\/265709\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>     \t<img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/972\/8e0\/b09\/9728e0b09d794a6793fa71d53cf6bf1a.jpg\"\/>  <\/p>\n<h4>\u0418\u043d\u0442\u0440\u043e<\/h4>\n<p>  \u0426\u0435\u043b\u044c \u2014 \u0441\u043e\u0437\u0434\u0430\u0442\u044c <s>\u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434<\/s> \u0441\u043a\u0440\u0438\u043f\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0431\u0435\u0436\u0438\u0442\u0441\u044f \u043f\u043e \u0441\u0430\u0439\u0442\u0443 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442 \u043a\u0430\u0436\u0434\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0441\u0430\u0439\u0442\u0430 \u043d\u0430 \u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0441\u0442\u044c html. <br \/>  \u042f \u0441\u043b\u044b\u0448\u0430\u043b, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043d\u0430\u043f\u0430\u0434\u0430\u0435\u0442 \u043f\u0435\u0440\u0444\u0435\u043a\u0446\u0438\u043e\u043d\u0438\u0437\u043c, \u0442\u043e \u043d\u0430\u0434\u043e \u043f\u043e\u043b\u0435\u0436\u0430\u0442\u044c, \u043e\u0442\u0434\u043e\u0445\u043d\u0443\u0442\u044c \u0438 \u044d\u0442\u043e \u043f\u0440\u043e\u0439\u0434\u0435\u0442. <br \/>  \u041f\u043e\u0434\u0443\u043c\u0430\u0435\u0448\u044c, \u0432 \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440\u0435 \u043e\u0448\u0438\u0431\u043a\u0430\u2026<br \/>  \u041d\u043e \u0435\u0441\u043b\u0438 \u0432\u0441\u0435 \u0436\u0435 \u043d\u0435 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442, \u0442\u043e <\/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-264613","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/264613","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=264613"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/264613\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=264613"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=264613"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=264613"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}