用自訂 user agent 表明你的身分

R 的網頁爬蟲

Timo Grossenbacher

Instructor

亮出你的身分!

  • Web 伺服器已會記錄你的 IP 位址
  • 最好主動表明身分
  • 有個 HTTP 標頭正是為此而設!

範例請求

1 https://developer.mozilla.org/en-US/docs/Web/HTTP/Overview
R 的網頁爬蟲

用 httr 修改標頭

response <- GET('http://example.com', user_agent("Hey, it's me, Timo! 
    Reach me at [email protected]."))

另一種作法:

set_config(add_headers(`User-Agent` = "Hey, it's me, Timo!
    Reach me at [email protected]."))
response <- GET('http://example.com')
R 的網頁爬蟲

一起來練習吧!

R 的網頁爬蟲

Preparing Video For Download...