R Change IP Address programmatically

7.7k Views Asked by At

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?

1

There are 1 best solutions below

8
On BEST ANSWER

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...