HTTP isteklerinin doğası

R ile Web Kazıma

Timo Grossenbacher

Instructor

Hypertext Transfer Protocol (HTTP)

Tarayıcıların sunucularla nasıl iletişim kurduğunu gösteren bir şema

1 https://developer.mozilla.org/en-US/docs/Web/HTTP/Overview
R ile Web Kazıma

İsteklerin yapısı

İstek web sunucusuna gönderilir

Örnek bir istek

Yaygın durum kodları: 200 (OK), 404 (NOT FOUND), 3xx (yönlendirmeler), 5xx (sunucu hataları)

Yanıt web sunucusundan alınır

Karşılık gelen yanıt

1 https://developer.mozilla.org/en-US/docs/Web/HTTP/Overview
R ile Web Kazıma

İstek yöntemleri: GET ve POST

  • GET: Veriyi göndermeden bir kaynağı getirir (GET /index.html)
  • POST: Sunucuya veri gönderir; ör. bir formu gönderdikten sonra
POST /test HTTP/1.1
Host: foo.example
Content-Type: application/x-www-form-urlencoded
Content-Length: 27

field1=value1&field2=value2

POST istekleri de bir yanıtla sonuçlanır!

1 https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
R ile Web Kazıma

httr ile HTTP istekleri

library(httr)
GET('https://httpbin.org')
Response [https://httpbin.org/]
  Date: 2020-09-19 13:02
  Status: 200
  Content-Type: text/html; charset=utf-8
  Size: 9.59 kB
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    ...
R ile Web Kazıma

httr ile HTTP istekleri

library(httr)
response <- GET('https://httpbin.org')
content(response)
{html_document}
<html lang="en">
[1] <head>\n<meta http-equiv="Content-Type" content="text/html; charset=UTF ...
[2] <body>\n    <a href="https://github.com/requests/httpbin" class="github ...
R ile Web Kazıma

Hadi pratik yapalım!

R ile Web Kazıma

Preparing Video For Download...