R 以编程方式更改 IP 地址 [英] R Change IP Address programmatically
问题描述
目前正在通过将不同的字符串传递给 html_session()
方法来更改 user_agent.
Currently changing user_agent by passing different strings to the html_session()
method.
有没有办法在抓取网站时更改计时器上的 IP 地址?
Is there also a way to change your IP address on a timer when scraping a website?
推荐答案
您可以通过 use_proxy
使用代理(更改您的 ip),如下所示:
You can use a proxy (which changes your ip) via use_proxy
as follows:
html_session("you-url", use_proxy("proxy-ip", port))
更多详情参见:?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")
第一次调用将返回您的 IP.第二次调用应该返回 138.201.63.123
作为 ip.
The first call will return your IP. The second call should return 138.201.63.123
as ip.
此代理取自 http://proxylist.hidemyass.com/ - 没有任何保证...
This Proxy was taken from http://proxylist.hidemyass.com/ - no garantees for anything...
这篇关于R 以编程方式更改 IP 地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!