Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 251
tonyk Avatar asked Jan 04 '17 14:01

tonyk


1 Answers

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

like image 183
Rentrop Avatar answered Nov 11 '22 02:11

Rentrop