tonyk
tonyk

Reputation: 368

R Change IP Address programmatically

Currently changing user_agent by passing different strings to the html_session() method.

Is there also a way to change your IP address on a timer when scraping a website?

Upvotes: 8

Views: 7969

Answers (1)

Rentrop
Rentrop

Reputation: 21497

You can use a proxy (which changes your ip) via use_proxy as follows:

html_session("you-url", use_proxy("proxy-ip", port))

For more details see: ?httr::use_proxy

To check if it is working you can do the following:

require(httr)

content(GET("https://ifconfig.co/json"), "parsed")
content(GET("https://ifconfig.co/json", use_proxy("138.201.63.123", 31288)), "parsed")

The first call will return your IP. The second call should return 138.201.63.123 as ip.

This Proxy was taken from http://proxylist.hidemyass.com/ - no garantees for anything...

Upvotes: 7

Related Questions