GithubHelp home page GithubHelp logo

layershifter / robots-txt-parser Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bopoda/robots-txt-parser

0.0 3.0 0.0 21 KB

php class for parse all directives from robots.txt files

License: MIT License

PHP 100.00%

robots-txt-parser's Introduction

robots-txt-parser

php класс для парса всех директив файла robots.txt.

Build Status

Попробовать demo работы класса RobotsTxtParser он-лайн.

Парсинг осуществляется по правилам в соответствии с Google & Yandex спецификациями. Specifications:

Это форк репозитория https://github.com/t1gor/Robots.txt-Parser-Class где я являлся контрибутором, но внесён ряд улучшений:

  1. парс директивы Clean-param в соответствии с clean-param синтаксисом
  2. удаление комментариев (everything following the '#' character, up to the first line break, is disregarded)
  3. улучшение парса host - межсекционная директива, должна относиться к user-agent '*'; при наличи нескольких host поисковики берут значение первой
  4. из класса удалены неиспользуеме методы, сделан рафакторинг, исправлена область видимости свойств класса
  5. добавлено больше тестовых кейсов, а также тестовые кейсы добавлены на весь новый функционал

Поддерживаемые директивы:

  • DIRECTIVE_ALLOW = 'allow';
  • DIRECTIVE_DISALLOW = 'disallow';
  • DIRECTIVE_HOST = 'host';
  • DIRECTIVE_SITEMAP = 'sitemap';
  • DIRECTIVE_USERAGENT = 'user-agent';
  • DIRECTIVE_CRAWL_DELAY = 'crawl-delay';
  • DIRECTIVE_CLEAN_PARAM = 'clean-param';

Usage example

$parser = new RobotsTxtParser(file_get_contents('http://example.com/robots.txt'));
var_dump($parser->getRules());
$parser = new RobotsTxtParser("
	User-Agent: *
	Disallow: /ajax
	Disallow: /search
	Clean-param: param1 /path/file.php

	User-agent: Yahoo
	Disallow: /

	Host: example.com
	Host: example2.com
");

var_dump($parser->getRules());
array(2) {
  ["*"]=>
  array(3) {
    ["disallow"]=>
    array(2) {
      [0]=>
      string(5) "/ajax"
      [1]=>
      string(7) "/search"
    }
    ["clean-param"]=>
    array(1) {
      [0]=>
      string(21) "param1 /path/file.php"
    }
    ["host"]=>
    string(11) "example.com"
  }
  ["yahoo"]=>
  array(1) {
    ["disallow"]=>
    array(1) {
      [0]=>
      string(1) "/"
    }
  }
}

robots-txt-parser's People

Watchers

James Cloos avatar Oleksandr Fediashov avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.