你知道如何使用免费的 ProxyScrape API 吗?本文将为您提供详细指导。
该 API 用于我们的免费代理列表,其返回的结果可在任何地方免费使用。
获取代理列表
https://api.proxyscrape.com/v2/?request=displayproxies&protocol=http&timeout=10000&country=all&ssl=all&anonymity=all
代码样本、
C#
var client = new RestClient("https://api.proxyscrape.com/v2/?request=displayproxies&protocol=http&timeout=10000&country=all&ssl=all&anonymity=all"); client.Timeout = -1; var request = new RestRequest(Method.GET); IRestResponse response = client.Execute(request); Console.WriteLine(response.Content);
CURL
curl --location --request GET 'https://api.proxyscrape.com/v2/?request=displayproxies&protocol=http&timeout=10000&country=all&ssl=all&anonymity=all'
飞镖 - Http
var request = http.Request('GET', Uri.parse('https://api.proxyscrape.com/v2/?request=displayproxies&protocol=http&timeout=10000&country=all&ssl=all&anonymity=all')); http.StreamedResponse response = await request.send(); if (response.statusCode == 200) { print(await response.stream.bytesToString()); } else { print(response.reasonPhrase); } }
围棋 - 本地
package main import ( "fmt" "net/http" "io/ioutil" ) func main() { url := "https://api.proxyscrape.com/v2/?request=displayproxies&protocol=http&timeout=10000&country=all&ssl=all&anonymity=all" method := "GET" client := &http.Client { } req, err := http.NewRequest(method, url, nil) if err != nil { fmt.Println(err return } res, err := client.Do(req) if err != nilNewRequest(method, url, nil) if err != nil { fmt.Println(err) return } res, err := client.Do(req) if err != nil { fmt.Println(err) return } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println(err) return } fmt.Println(string(body)) }
超文本传输协定
GET /v2/?request=displayproxies&protocol=http&timeout=10000&country=all&ssl=all&anonymity=all HTTP/1.1 Host: api.proxyscrape.com
java okhttp
OkHttpClient client = new OkHttpClient().newBuilder() .build(); Request request = new Request.Builder() .url("https://api.proxyscrape.com/v2/?request=displayproxies&protocol=http&timeout=10000&country=all&ssl=all&anonymity=all") .method("GET", null) .build(); Response response = client.newCall(request).execute();
JavaScript - 抓取
var requestOptions = { method: 'GET', redirect: 'follow' }; fetch("https://api.proxyscrape.com/v2/?request=displayproxies&protocol=http&timeout=10000&country=all&ssl=all&anonymity=all", requestOptions) .then(response => response.text()) .then(result => console.log(result)) .catch(error => console.log('error', error));
JavaScript - jQuery
var settings = { "url":"https://api.proxyscrape.com/v2/?request=displayproxies&protocol=http&timeout=10000&country=all&ssl=all&anonymity=all", "method":"GET", "timeout":0, }; $.ajax(settings).done(function (response) { console.log(response); });
JavaScript - XHR
var xhr = new XMLHttpRequest(); xhr.withCredentials = true; xhr.addEventListener("readystatechange", function() { if(this.readyState === 4) { console.log(this.responseText); }.}); xhr.open("GET", "https://api.proxyscrape.com/v2/?request=displayproxies&protocol=http&timeout=10000&country=all&ssl=all&anonymity=all"); xhr.send();
C - libcurl
CURL *curl; CURLcode res; curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET"); curl_easy_setopt(curl, CURLOPT_URL, "https://api.proxyscrape.com/v2/?request=displayproxies&protocol=http&timeout=10000&country=all&ssl=all&anonymity=all"); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");struct curl_slist *headers = NULL; curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); res = curl_easy_perform(curl); } curl_easy_cleanup(curl);
NodeJs - Axios
var axios = require('axios'); var config = { method: 'get', url:https://api.proxyscrape.com/v2/?request=displayproxies&protocol=http&timeout=10000&country=all&ssl=all&anonymity=all', headers:{ }}; axios(config) .then(function (response) { console.log(JSON.stringify(response.data)); }) .catch(function (error) { console.log(error); });
NodeJs - 本地
var https = require('follow-redirects').https; var fs = require('fs'); var options = { 'method': 'GET', 'hostname': 'api.proxyscrape.com', 'path': '/v2/?request=displayproxies&protocol=http&timeout=10000&country=all&ssl=all&anonymity=all', 'headers': { }, 'maxRedirects': 20 }; var req = https.request(options, function (res) { var chunks = []; res.on("data", function (chunk) { chunks.push(chunk); }); res.on("end", function (chunk) { var body = Buffer.concat(chunks); console.log(body.toString()); }); res.on("error", function (error) { console.error(error); }); }); req.end();
DNodeJs - 请求
var request = require('request'); var options = { 'method': 'GET', 'url': 'https://api.proxyscrape.com/v2/?request=displayproxies&protocol=http&timeout=10000&country=all&ssl=all&anonymity=all', 'headers': { }.}; request(options, function (error, response) { if (error) throw new Error(error); console.log(response.body); });
PHP - cURL
'https://api.proxyscrape.com/v2/?request=displayproxies&protocol=http&timeout=10000&country=all&ssl=all&anonymity=all', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => ''、CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', ));$response = curl_exec($curl); curl_close($curl); echo $response;
Python - http.client
import http.client conn = http.client.HTTPSConnection("api.proxyscrape.com") payload = '' headers = {} conn.request("GET", "/v2/?request=displayproxies&protocol=http&timeout=10000&country=all&ssl=all&anonymity=all", payload, headers) res = conn.getresponse() data = res.read() print(data.decode("utf-8"))
Python - 请求
import requests url = "https://api.proxyscrape.com/v2/?request=displayproxies&protocol=http&timeout=10000&country=all&ssl=all&anonymity=all" payload={} headers = {} response = requests.request("GET", url, headers=headers, data=payload) print(response.text)
Ruby - Net::HTTP
require "uri" require "net/http" url = URI("https://api.proxyscrape.com/v2/?request=displayproxies&protocol=http&timeout=10000&country=all&ssl=all&anonymity=all") https = Net::HTTP.new(url.host, url.port) https.use_ssl = true request = Net::HTTP::Get.new(url) response = https.request(request) puts response.read_body
外壳 - Httpie
http --follow --timeout 3600 GET 'https://api.proxyscrape.com/v2/?request=displayproxies&protocol=http&timeout=10000&country=all&ssl=all&anonymity=all'
外壳 - 获取
wget --no-check-certificate --quiet \ --method GET \ --timeout=0 \ --header '' \ 'https://api.proxyscrape.com/v2/?request=displayproxies&protocol=http&timeout=10000&country=all&ssl=all&anonymity=all'
Swift - URLSession
import Foundation #if canImport(FoundationNetworking) import FoundationNetworking #endif var semaphore = DispatchSemaphore (value: 0) var request = URLRequest(url:URL(string:"https://api.proxyscrape.com/v2/?request=displayproxies&protocol=http&timeout=10000&country=all&ssl=all&anonymity=all")!,timeoutInterval:request.httpMethod = "GET" let task = URLSession.shared.dataTask(with: request) { data, response, error in guard let data = data else { print(String(describing: error)) semaphore.signal() return } print(String(data: data, encoding: .utf8)!) semaphore.signal() } task.resume() semaphore.wait()
参数
要求 | 显示代理 定义代理是在浏览器中下载还是显示。可能的值
|
规程 | http 应下载的代理协议。可能的值
如果要同时下载两个协议,可以用逗号分隔这些值,例如:protocol=socks4,socks5 |
超时 | 10000 应下载代理的最大超时(毫秒)。 |
国家 | 一应俱全 国家参数可以是任何 Alpha 2 ISO 国家代码或 "全部"。未定义国家时,国家将自动设置为 "全部"。您也可以在一个请求中使用多个国家,方法是用逗号分隔它们。 |
ssl | 一应俱全 代理服务器是否支持 SSL(HTTPS)?此参数仅用于下载 HTTP 代理服务器。 |
匿名性 | 一应俱全 定义代理应具有的匿名级别:
如果未定义匿名级别,则默认为 "全部"。您也可以在一个请求中使用多个匿名级别,方法是用逗号分隔它们。 |
请求示例:
变异 要求 = http.要求(GET, 乌里.解析('https://api.proxyscrape.com/v2/?request=displayproxies&protocol=http&timeout=10000&country=all&ssl=all&anonymity=all'));
http.StreamedResponse 响应 = 等 要求.发送();
如果 (回应.状态代码 == 200) {
打印(等 回应.溪流.字节到字符串());
}
不然 {
打印(回应.原因);
}
获取代理列表详情
https://api.proxyscrape.com/v2/?request=proxyinfo
此 API 端点将返回可用代理的信息,例如
- 可用代理权数量
- 代理列表上次更新后的时间
- 可用国家
- 代理机构的相关组织
- 代理端口
此 API 端点还支持 "获取代理列表 "中描述的所有参数。
参数
要求 | 代理信息 |
简化 | 真 如果只想接收可用代理的数量,请使用此参数。 |
申请示例
变异 要求 = http.要求(GET, 乌里.解析('https://api.proxyscrape.com/v2/?request=proxyinfo'));
http.StreamedResponse 响应 = 等 要求.发送();
如果 (回应.状态代码 == 200) {
打印(等 回应.溪流.字节到字符串());
}
不然 {
打印(回应.原因);
}
参考资料
免责声明:这部分内容主要来自商家。如果商家不希望在我的网站上显示,请 联系我们 删除您的内容。
最后更新于 2023 年 12 月 12 日