PHP和Python接入HTTP代理的区别

在这里插入图片描述
Python和PHP都是解释动态类型的高级脚本语言。

在互联网上,PHP有一个专业化的方向,现在,专业化也是所有行业的趋势。

PHP接入HTTP代理ip代码

Php http/sock5:

// 要访问的目标页面
        $targetUrl = "http://h.zhimaruanjian.com/?utm-source=xianyu&utm-keyword=?1";
        // 代理服务器
        $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);

Python更为一般,它可以做任何事情。能够进行WEB相关工作,但不像php那样专业和简单。从语法上来说,PHP的语法属于C系,继承了C++和Java的许多传统优势。

Python的语法,吸收了一些现代语言元素,如通过缩进确定层次,lambda表达式,columns生成器,一级函数对象。二是值得我们学习掌握的!
Python接入HTTP代理ip代码

#coding=utf-8
import requests
#请求地址
targetUrl = "http://h.zhimaruanjian.com/?utm-source=xianyu&utm-keyword=?1"
#代理服务器
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_code
print resp.text

毋庸置疑,PHP和Python是非常流行的。尽管PHP和Python不支持某个项目,但某些项目经理和客户仍然将使用它们作为优先事项。而PHP更是占据了互联网市场80%的绝对优势。

最困难的决定之一就是选择第一种编程语言,PHP和Python都值得我们关注。两者都提供了很多学习机会,包括方便用户使用的语法检查工具,使得学习过程更加简单,并且有坚实的语言基础。
在这里插入图片描述
建议初学者可以试一下两种语言,借助优质代理ip学习Python,肯定能起到事半功倍的效果。

猜你喜欢

转载自blog.csdn.net/zhimaHTTP/article/details/114945831
今日推荐