Change IP address dynamically?

前端 未结 7 595

Consider the case, I want to crawl websites frequently, but my IP address got blocked after some day/limit.

So, how can change my IP address dynamically or any other id

7条回答
  •  既然无缘
    2021-01-29 19:21

    If you are using R, you could do the web crawling through TOR. I think TOR resets its IP-adress every 10 minutes(?) automatically. I think there is a way forcing TOR to change the IP in shorter intervals, but that didn't work for me. Instead you could set up multiple instances of TOR and then switch between the independent instances (here you can find a good explaination of how to set up multiple instances of TOR: https://tor.stackexchange.com/questions/2006/how-to-run-multiple-tor-browsers-with-different-ips)

    After that you could do something like the following in R (use the ports of your independent TOR browsers and a list of useragents. Every time you call the 'getURL'-function cycle through your list of ports/useragents)

    library(RCurl)
    
    port <- c(a list of your ports)
    proxy <- paste("socks5h://127.0.0.1:",port,sep="")
    ua <- c(a list of your useragents)
    
    opt <- list(proxy=sample(proxy,1),
                useragent=sample(ua,1),
                followlocation=TRUE,
                referer="",
                timeout=timeout,
                verbose=verbose,
                ssl.verifypeer=ssl)
    
    webpage <- getURL(url=url,.opts=opt)
    

提交回复
热议问题