Hands-on teaching you to play with proxy IP with PowerShell
Today we're going to talk about the one that comes with Windows.Invoke-WebRequestCommand (iwr for short), this thing is great when messing around with network requests. Especially when you have to work with proxy IP, can solve a lot of practical problems. For example, to do data collection ah, test the stability of the service ah these scenarios, with the right proxy IP can make you twice as much effort.
Basic Usage Example
$response = Invoke-WebRequest -Uri "http://example.com"
$response.Content
Put a "vest" on the request.
Want your web requests to have a different identity? Just add a proxy parameter directly to the command. Here's the recommended way to do itipipgos dynamic IP pool, the quality of their residential proxies is solid as hell. Pay attention to this-ProxyUsage of the parameter:
The right way to open a proxy IP
$proxy = "123.123.123.123:8888"
iwr -Uri "https://target-site.com" -Proxy $proxy
Remember them when using ipipgo!API Access, get fresh IP every time. for example, their extraction link looks like this:
http://api.ipipgo.com/get?key=你的密钥&count=5
Three points of the guide to avoiding the pit
Newbies often fall into these three potholes:
- The proxy format is misspelled ashttp://Beginning (not actually required)
- Forgetting to handle SSL certificate validation (plus-UseBasicParsing(Parameters)
- Not setting a timeout causes it to get stuck (with the-TimeoutSec(Parameters)
See here for the correct full pose:
iwr -Uri "https://需要访问的网址" `
-Proxy "Proxy IP:port provided by ipipgo" `
-UseBasicParsing `
-TimeoutSec 30
Practical case: e-commerce price monitoring
Suppose you want to monitor the price of an e-commerce product, you can avoid being blocked by rotating IPs with ipipgo. Here is aAutomatic IP switchingExamples of:
Get 10 IPs from ipipgo into the array
$ipPool = @('111.222.33.44:8888','55.66.77.88:8888',... ,'99.88.77.66:8888')
foreach ($item in 1..100) {
$currentProxy = $ipPool[(Get-Random -Maximum 10)]
try {
$resp = iwr -Uri "product link" -Proxy $currentProxy
Parsing the price code...
break
} catch {
Write-Host "Try again with a different IP..."
}
}
QA Frequently Asked Questions
concern | cure |
---|---|
Proxies suddenly failing? | Use ipipgo's pay-per-volume package and set an auto-switching threshold |
A 407 authentication error occurs | Add the account password to the proxy parameters:-ProxyCredential |
Highly anonymous proxy required | Go with ipipgo.Residential Agentstype, request header without X-Proxy field |
Why recommend ipipgo
There are so many proxy service providers on the market, but theipipgoThere are three major killers:
- Exclusive IP Survival Detection Mechanism (automatically eliminates failed nodes)
- Local IP resources of 23 provincial administrative regions in China
- Support byNumber of requestsBilling (suitable for small-scale requirements)
And finally.Hidden Tips: with ipipgo'sAPI model
When getting the proxy, add the&type=https
parameter can directly get a list of proxies that support HTTPS, saving you the trouble of sifting through them yourself.