帮助中心
java语言如何接入代码demo
发布时间 2022-05-09
MAVEN引入如下依赖包:<dependencies><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.3.5</version></dependency><dependency><groupId>com.squareup.okhttp3</groupId><artifactId>okhttp</artifactId><version>4.7.1</version></dependency></dependencies>复制下面代码,新建Package:com.demo --> 新建Java类:Mainpackage com.demo;import cn.hutool.http.HttpUtil;import okhttp3.*;import java.io.*;import java.net.InetSocketAddress;import java.net.Proxy;import java.util.Objects;import java.util.concurrent.TimeUnit;public class Main {//    需要请求的目标网址private static final String TARGET_URL = "目标网址";//    提取链接private static final String API_URL = "提取链接";public static void main(String[] args) {String result = HttpUtil.get(API_URL);System.out.println("从接口获取回来:" + result.strip());String proxyIp = result.strip();try {Proxies(TARGET_URL, proxyIp);Thread.sleep(500);} catch (Exception e) {e.printStackTrace();}}public static void Proxies(String urlString, String ipPort) {try {Response response = null;try {System.out.println("数据资源:" + ipPort);String ip = ipPort.split(":")[0];int port = Integer.parseInt(ipPort.split(":")[1]);Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(ip, port));OkHttpClient httpClient = new OkHttpClient().newBuilder().proxy(proxy).connectTimeout(10, TimeUnit.SECONDS).build();Request request = null;request = (new Request.Builder().url(urlString).build());response = httpClient.newCall(request).execute();System.out.println("输出结果2:" + Objects.requireNonNull(response.body()).string());} catch (IOException e) {System.out.println("请求出错1");e.printStackTrace();}} catch (Exception e) {System.out.println("请求出错2");e.printStackTrace();}}}
PHP语言如何接入代码demo
发布时间 2022-05-09
Php http/sock5:// 要访问的目标页面        $targetUrl = "http://baidu.com";        // 代理服务器        $proxyServer = "http":"http://ip:port";        // 隧道身份信息        $ch = curl_init();        curl_setopt($ch, CURLOPT_URL, $targetUrl);        curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, false);        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);        // 设置代理服务器//        curl_setopt($ch, CURLOPT_PROXYTYPE, 0); //http        curl_setopt($ch, CURLOPT_PROXYTYPE, 5); //sock5        curl_setopt($ch, CURLOPT_PROXY, $proxyServer);        // 设置隧道验证信息        curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727;)");        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);        curl_setopt($ch, CURLOPT_TIMEOUT, 5);        curl_setopt($ch, CURLOPT_HEADER, true);        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);        $result = curl_exec($ch);        curl_close($ch);        var_dump($result);
C语言如何接入代码demo
发布时间 2022-05-09
*代理模式: 为其他对象提供一种代理以控制对这个对象的访问*//*普通代理:  调用者只能访问代理角色,而不能访问真实角色。 调用者只知道代理而不用知道真实角色,屏蔽了真实角色的变更对高层模块的影响。*#include#include#include/*抽象游戏者  代理*/typedef struct _IGamePlayer IGamePlayer;struct _IGamePlayer{    void (*login)(char *pName, char *pPassword, void *);    void (*killBoss)(void *);    void (*upgrade)(void *);    void (*DeleteIGamePlayer)(void *);};/*游戏者   具体*/typedef struct _GamePlayer GamePlayer;struct _GamePlayer{    IGamePlayer gmplayer;   /*继承抽象游戏者*/    char acName[10];        /*游戏者姓名*/    void (*DeleteGamePlayer)(GamePlayer *pGamePlayer);};void login(char *pName, char *pPassword, void *pGamePlayer){    printf("user :%s is login in !\n", pName);}void killBoss(void *pGamePlayer){    printf("%s is killing the boss! \n", ((GamePlayer *)pGamePlayer)->acName);}void upgrade(void *pGamePlayer){    printf("%s is upgrading !\n", ((GamePlayer *)pGamePlayer)->acName);}void DeleteGamePlayer(GamePlayer *pGamePlayer){    if(pGamePlayer)    {        free(pGamePlayer);        pGamePlayer = NULL;    }}GamePlayer *CreateGamePlayer(IGamePlayer *pIGamePlayer, char *pName){    GamePlayer *pGamePlayer = NULL;    if(!pIGamePlayer)    {        return NULL;    }    else    {        pGamePlayer = (GamePlayer *)malloc(sizeof(GamePlayer));        if(!pGamePlayer)        {            return NULL;        }        memset(pGamePlayer, 0, sizeof(GamePlayer));        strcpy(pGamePlayer->acName, pName);        pGamePlayer->DeleteGamePlayer = DeleteGamePlayer;        pGamePlayer->gmplayer.login = login;        pGamePlayer->gmplayer.killBoss = killBoss;        pGamePlayer->gmplayer.upgrade = upgrade;        pGamePlayer->gmplayer.DeleteIGamePlayer = pGamePlayer->DeleteGamePlayer;        return pGamePlayer;    }}/*普通代理的代理者*/typedef struct _GamePlayerProxy GamePlayerProxy;struct _GamePlayerProxy{    IGamePlayer gmplayer;   /*继承抽象游戏者*/    GamePlayer *pGamePlayer; /*被代理者*/    void (*DeleteGamePlayerProxy)(GamePlayerProxy *pGamePlayerProxy);};void ProxykillBoss(void * pGamePlayerProxy){((GamePlayerProxy *)pGamePlayerProxy)->pGamePlayer->gmplayer.killBoss(((GamePlayerProxy *)pGamePlayerProxy)->pGamePlayer);    /*代理执行被代理者的方法*/}void Proxylogin(char *pName, char *pPassword, void *pGamePlayerProxy){    ((GamePlayerProxy *)pGamePlayerProxy)->pGamePlayer->gmplayer.login(pName, pPassword, pGamePlayerProxy);}void Proxyupgrade(void *pGamePlayerProxy){    ((GamePlayerProxy *)pGamePlayerProxy)->pGamePlayer->gmplayer.upgrade(((GamePlayerProxy *)pGamePlayerProxy)->pGamePlayer);}void DeleteGamePlayerProxy(GamePlayerProxy *pGamePlayerProxy){    if(pGamePlayerProxy->pGamePlayer)    {        pGamePlayerProxy->pGamePlayer->DeleteGamePlayer(pGamePlayerProxy->pGamePlayer);    }    if(pGamePlayerProxy)    {        free(pGamePlayerProxy);        pGamePlayerProxy = NULL;    }    return;}GamePlayerProxy *CreateProxy(char *pName){    GamePlayerProxy *pGamePlayerProxy = NULL;    pGamePlayerProxy = (GamePlayerProxy *)malloc(sizeof(GamePlayerProxy));    if(!pGamePlayerProxy)    {        return NULL;    }    memset(pGamePlayerProxy, 0, sizeof(GamePlayerProxy));    pGamePlayerProxy->pGamePlayer = CreateGamePlayer(                            (IGamePlayer *)pGamePlayerProxy, pName);  /*创建被代理者*/    pGamePlayerProxy->DeleteGamePlayerProxy = DeleteGamePlayerProxy;    pGamePlayerProxy->gmplayer.login = Proxylogin;    pGamePlayerProxy->gmplayer.killBoss = ProxykillBoss;    pGamePlayerProxy->gmplayer.upgrade = Proxyupgrade;    pGamePlayerProxy->gmplayer.DeleteIGamePlayer = pGamePlayerProxy->DeleteGamePlayerProxy;    return pGamePlayerProxy;}/*场景*/void main(){    /*定义一个代理者*/    IGamePlayer *pPlayProxy = (IGamePlayer *)CreateProxy("zhangsan"); //转换为抽象类, 即场景只依赖于抽象类    /*开始打游戏,记下时间戳*/    printf("game start time is : 2014-1-21 9:00\n");    /*代理登录*/    pPlayProxy->login("zhangsan", "password", pPlayProxy);    /*代理打怪*/    pPlayProxy->killBoss(pPlayProxy);    /*代理升级*/    pPlayProxy->upgrade(pPlayProxy); /*游戏结束*/    printf("game end time is :2014-1-21 10:00");    /*释放资源*/    pPlayProxy->DeleteIGamePlayer(pPlayProxy);}
go语言如何接入代码demo
发布时间 2022-05-09
go语言启用资源:package mainimport ("fmt""io/ioutil""net/http""net/url")//sock5func socksproxy() {urli := url.URL{}urlproxy, _ := urli.Parse("http://测试:端口")client := &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(urlproxy),},}rqt, err := http.NewRequest("GET", "http://myip.top", nil)if err != nil {println("接口获取失败!")return}rqt.Header.Add("User-Agent", "Lingjiang")//处理返回结果response, _ := client.Do(rqt)defer response.Body.Close()body, err := ioutil.ReadAll(response.Body)if err != nil {return}fmt.Println("socks5:", string(body))return}//http代理func httpproxy() {urli := url.URL{}urlproxy, _ := urli.Parse("http://测试:端口")client := &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(urlproxy),},}rqt, err := http.NewRequest("GET", "http://myip.top", nil)if err != nil {println("接口获取失败!")return}rqt.Header.Add("User-Agent", "Lingjiang")//处理返回结果response, _ := client.Do(rqt)defer response.Body.Close()body, err := ioutil.ReadAll(response.Body)if err != nil {return}fmt.Println("http:", string(body))return}//本机地址func httplocal() {client := &http.Client{}rqt, err := http.NewRequest("GET", "http://myip.top", nil)if err != nil {println("接口获取失败!")return}rqt.Header.Add("User-Agent", "Lingjiang")//处理返回结果response, _ := client.Do(rqt)defer response.Body.Close()body, err := ioutil.ReadAll(response.Body)if err != nil {return}fmt.Println("本机:", string(body))return}func main() {httplocal()httpproxy()socksproxy()}
Python如何接入代码demo
发布时间 2022-05-09
代码参考:#coding=utf-8import requests#请求地址targetUrl = "https://www.baidu.com"#代理服务器proxyHost = "ip"proxyPort = "port"proxyMeta = "http://%(host)s:%(port)s" % {    "host" : proxyHost,    "port" : proxyPort,}#pip install -U requests[socks]  socks5 # proxyMeta = "socks5://%(host)s:%(port)s" % {#     "host" : proxyHost,#     "port" : proxyPort,# }proxies = {    "http"  : proxyMeta,    "https"  : proxyMeta}resp = requests.get(targetUrl, proxies=proxies)print resp.status_codeprint resp.text
Selenium语言如何接入代码demo
发布时间 2022-05-09
Selenium启用资源:Python selenium http/socks5:#coding=utf-8from selenium import webdriver# 代理服务器proxyHost = "ip"proxyPort = "port"proxyType='http' #socks5# 代理隧道验证信息service_args = [    "--proxy-type=%s" % proxyType,    "--proxy=%(host)s:%(port)s" % {        "host" : proxyHost,        "port" : proxyPort,    }    ]# 要访问的目标页面targetUrl = "http://baidu.com"driver = webdriver.PhantomJS(service_args=service_args)driver.get(targetUrl)print driver.titleprint driver.page_source.encode("utf-8")driver.quit()
Phantomjs语言如何接入代码demo
发布时间 2022-05-09
phantomjs 可通过以下设置#coding=utf-8import osimport reimport timeimport requestsfrom scrapy.selector import HtmlXPathSelectorfrom scrapy.http import HtmlResponsefrom selenium import webdriverfrom selenium.webdriver.common.proxy import ProxyTypeimport sysreload(sys)sys.setdefaultencoding("utf-8")import warningswarnings.filterwarnings("ignore")if __name__ == '__main__':PATH_PHANTOMJS=r'D:\phantomjs\bin\phantomjs.exe'browser=webdriver.PhantomJS(PATH_PHANTOMJS)#真实地址browser.get('http://icanhazip.com/') #获取网址response = HtmlResponse(url='',body=str(browser.page_source))hxs = HtmlXPathSelector(response)print 'your ip is:',''.join(hxs.select('//text()').extract()).strip()#资源proxy=webdriver.Proxy()proxy.proxy_type=ProxyType.MANUALproxy.http_proxy='220.248.229.45:3128'#将代理设置添加到webdriver.DesiredCapabilities.PHANTOMJS中proxy.add_to_capabilities(webdriver.DesiredCapabilities.PHANTOMJS)browser.start_session(webdriver.DesiredCapabilities.PHANTOMJS)browser.get('http://icanhazip.com/') #获取网址response = HtmlResponse(url='',body=str(browser.page_source))hxs = HtmlXPathSelector(response)print 'your proxy ip is:',''.join(hxs.select('//text()').extract()).strip()重点接入代码:Phantomjs http/socks5:phantomjs --proxy=ip:port --proxy-type=[http|socks5|none] demo.js