[TIL] HTTP : The Definitive Guide "p232 ~ p234"

시윤·2025년 3월 3일
0

[TIL] Two Pages Per Day

목록 보기
96/107
post-thumbnail

Chapter 9. Web Robots

(해석 또는 이해가 잘못된 부분이 있다면 댓글로 편하게 알려주세요.)


✏️ 원문 번역


robots.txt File Format

The robots.txt file has a very simple, line-oriented syntax. There are three types of lines in a robots.txt file:blank lines, comment lines, and rule lines. Rule lines look like HTTP headers (<Field>: <value>) and are used for pattern matching. For example:

# this robots.txt file allows Slurp & Webcrawler to crawl
# the public parts of our site, but no other robots...

User-Agent: slurp
User-Agent: webcrawler
Disallow: /private

User-Agent: *
Disallow:
  • robots.txt 파일은 매우 단순한 라인 기반의 문법을 가지고 있습니다.

  • robots.txt 파일에는 file:blank 라인, comment 라인, rule 라인 세 가지가 있습니다.

  • rule 라인은 마치 HTTP 헤더처럼 생겨 패턴 매칭에 사용됩니다.

The lines in a robots.txt file are logically separated into “records.” Each record describes a set of exclusion rules for a particular set of robots. This way, different exclusion rules can be applied to different robots.

  • robots.txt 파일의 라인은 논리적인 레코드로 구분됩니다.

  • 각각의 레코드는 특정 로봇 집합에 대한 예외 규칙 집합을 나타냅니다.

  • 다양한 예외 규칙이 다양한 로봇에게 적용되고 있는 것입니다.

Each record consists of a set of rule lines, terminated by a blank line or end-of-file character. A record starts with one or more User-Agent lines, specifying which robots are affected by this record, followed by Disallow and Allow lines that say what URLs these robots can access.

  • 레코드는 규칙 라인 집합으로 구성되어 있으며 공백이나 EOF 문자로 끝납니다.

  • 하나 이상의 User-Agent 라인으로 시작하여 레코드에 영향을 받는 로봇을 한정합니다.

  • 그 뒤로 로봇이 접근할 수 있는 URL이 무엇인지를 나타내는 Disallow 및 Allow 라인이 따릅니다.

The previous example shows a robots.txt file that allows the Slurp and Web crawler robots to access any file except those files in the private subdirectory. The same file also prevents any other robots from accessing anything on the site.

  • 이전의 예시는 Slurp과 Webcrawler 로봇이 비공개 하위 디렉토리를 제외한 모든 파일에 접근하는 것을 허용하는 robots.txt 파일입니다.

  • 동시에 다른 로봇이 사이트의 파일에 접근하는 것을 막습니다.

Let’s look at the User-Agent, Disallow, and Allow lines.

  • User-Agent와 Disallow, Allow 라인에 대해 각각 살펴봅시다.

The User-Agent line

Each robot’s record starts with one or more User-Agent lines, of the form:

User-Agent: <robot-name>
or:
User-Agent: *
  • 로봇의 레코드는 하나 이상의 User-Agent 라인으로 시작합니다.

The robot name (chosen by the robot implementor) is sent in the User-Agent header of the robot’s HTTP GET request.

  • 로봇 구현자에 의해 지정된 로봇의 이름은 HTTP GET 요청의 User-Agent 헤더에 실어 전송합니다.

When a robot processes a robots.txt file, it must obey the record with either:

• The first robot name that is a case-insensitive substring of the robot’s name
• The first robot name that is “*”

  • 로봇이 robots.txt 파일을 처리할 때 둘 중 하나가 포함된 레코드를 따라야 합니다.
    • 대소문자 구별이 없는 하위 문자열에 해당하는 첫 번째 로봇의 이름
    • "*"로 표시된 첫 번째 로봇의 이름

If the robot can’t find a User-Agent line that matches its name, and can’t find a wild-carded “User-Agent: *” line, no record matches, and access is unlimited.

  • 로봇이 자신의 이름과 일치하는 User-Agent 라인을 찾을 수 없고 "User-Agent: *" 구문도 찾을 수 없다면 일치하는 레코드가 없는 것이므로 접근이 제한되지 않습니다.

Because the robot name matches case-insensitive substrings, be careful about false matches. For example, “User-Agent: bot” matches all the robots named Bot, Robot, Bottom-Feeder, Spambot, and Dont-Bother-Me.

  • 로봇의 이름은 대소문자 구분이 없는 하위 문자열으므로 잘못된 매치가 발생하지 않도록 주의해야 합니다.

  • 예를 들어 "User-Agent: bot"은 Bot, Robot, Bottom-Feeder, Spambot, Dont-Bother-Me와 같은 모든 로봇에 매치됩니다.


The Disallow and Allow lines

The Disallow and Allow lines immediately follow the User-Agent lines of a robot exclusion record. They describe which URL paths are explicitly forbidden or explicitly allowed for the specified robots.

  • Disallow와 Allow 라인은 예외 레코드의 User-Agent 라인에 뒤따릅니다.

  • 특정 로봇에 대해 명시적으로 접근이 금지되거나 허용되는 URL 경로를 나타냅니다.

The robot must match the desired URL against all of the Disallow and Allow rules for the exclusion record, in order. The first match found is used. If no match is found, the URL is allowed.

  • 로봇은 예외 레코드에 대한 모든 Disallow 및 Allow 규칙에 목표 URL을 순서대로 매치해야 합니다.

  • 첫 번째로 일치한 규칙이 적용됩니다.

  • 만약 일치하는 URL이 없다면 URL이 허용됩니다.

For an Allow/Disallow line to match a URL, the rule path must be a case-sensitive prefix of the URL path. For example, “Disallow: /tmp” matches all of these URLs:

http://www.joes-hardware.com/tmp
http://www.joes-hardware.com/tmp/
http://www.joes-hardware.com/tmp/pliers.html
http://www.joes-hardware.com/tmpspc/stuff.txt


Disallow/Allow prefix matching

Here are a few more details about Disallow/Allow prefix matching:

  • Disallow/Allow 접두사 매칭에 대한 몇 가지 상세 정보입니다.

• Disallow and Allow rules require case-sensitive prefix matches. The asterisk has no special meaning (unlike in User-Agent lines), but the universal wildcarding effect can be obtained from the empty string.

  • Disallow 및 Allow 규칙은 대소문자 구분이 있는 접두사 매칭을 필요로 합니다.

  • asterisk(*)는 User-Agent 라인과 달리 특별한 의미를 가지고 있지 않지만 빈 문자열에서 전역적인 와일드카드 효과를 얻을 수 있습니다.

• Any “escaped” characters (%XX) in the rule path or the URL path are unescaped back into bytes before comparison (with the exception of %2F, the forward slash, which must match exactly).

  • 규칙 경로나 URL에 포함된 모든 탈출 문자(%XX)는 비교하기 전 바이트 단위로 디코딩됩니다.

  • 단 정확히 일치해야 하는 슬래시(%2F)는 제외됩니다.

• If the rule path is the empty string, it matches everything.

  • 만약 모든 규칙 경로가 빈 문자열이라면 모든 것에 매치됩니다.

Table 9-3 lists several examples of matching between rule paths and URL paths.

  • Table 9-3은 규칙 경로와 URL 사이의 매칭 예시입니다.

Prefix matching usually works pretty well, but there are a few places where it is not expressive enough. If there are particular subdirectories for which you also want to disallow crawling, regardless of what the prefix of the path is, robots.txt provides no means for this. For example, you might want to avoid crawling of RCS version control subdirectories. Version 1.0 of the robots.txt scheme provides no way to support this, other than separately enumerating every path to every RCS subdirectory.

  • 접두사 매칭은 대체로 잘 동작하지만 충분히 표현되지 않는 경우도 존재합니다.

  • 경로의 접두사가 무엇이든 상관없이 크롤링을 허용하고 싶지 않은 특정 하위 디렉토리에 대해서는 robots.txt에게 제어 수단을 제공하지 않습니다.

  • 예를 들어 RCS 버전 제어 하위 디렉토리에 대한 크롤링을 금지하고 싶다고 가정합니다.

  • robots.txt v1.0은 이를 지원할 방법이 없기 때문에 모든 RCS 하위 디렉토리에 대한 경로를 각각 나열할 수밖에 없습니다.


✏️ 요약


robots.txt File Format

  • robots.txt는 File:blank 라인과 Comment 라인, Rule 라인으로 구성

  • Record(레코드) : 특정 로봇 집합에 대한 규칙 집합

    • 레코드는 하나 이상의 User-Agent 라인으로 시작

    • User-Agent : 규칙을 적용할 로봇 집합

      • Case-insensitive : 대소문자 구분 X
      • Substring : 문자열의 포함 여부를 확인
      • * : 모든 로봇에 대해 적용
    • Disallow/Allow : 로봇 집합에 대해 접근이 금지되거나 허용되는 URL

      • 모든 레코드에 대해 목표 URL을 순서대로 매치하여 첫 번째로 일치하는 규칙 적용
      • Case-sensitive : 대소문자 구분 O
      • Prefix : 접두사로 표시
      • URL의 모든 탈출 문자는 바이트 단위로 디코딩하여 표현(%2F 제외)

✏️ 감상


예측학습으로 위기 모면하기

어제 robots.txt 문법을 안 찾아봤다면 오늘 독해가 조금 어려웠을 것 같다. 영어는 왜 이렇게 어려운 걸까 ㅠㅁㅠ

profile
맑은 눈의 다람쥐

0개의 댓글

관련 채용 정보