pyspider配置帶驗(yàn)證的squid代理池

就是這樣的:

crawl_config = {

? ? ? ? "proxy":"用戶名:密碼@你的代理池ip:6666"

}

首先要安裝squid(centos下)

yum install -y squid

作者都推薦squid,那么就用吧~

添加squid的用戶驗(yàn)證

htpasswd -c /etc/squid/passwd 用戶名

根據(jù)提示輸入兩次密碼

如果找不到htpasswd, 執(zhí)行

yum install httpd

然后繼續(xù)上一步。

然后根據(jù)這個(gè)配置文件覆蓋/etc/squid/squid.conf文件


http_port 6666 #對(duì)外公布的端口

#緩存大小

cache_mem 128 MB

maximum_object_size 16 MB

cache_dir ufs /var/spool/squid 100 16 256

access_log /var/log/squid/access.log

auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwd #指定認(rèn)證程序以及賬戶文件

#auth_param basic children 50 #同時(shí)連接的客戶端數(shù)量

# 定義端口

acl Safe_ports port 80? ? ? # http

acl SSL_ports port 443

acl CONNECT method CONNECT

acl auth_user proxy_auth REQUIRED

# 拒絕所有非定義的端口?

http_access deny !Safe_ports

http_access allow auth_user

# 拒絕所有非定義的端口

http_access deny CONNECT !SSL_ports

http_access deny all

via off

forwarded_for delete

#forwarded_for off

#文件最后加上? 高匿配置?

request_header_access X-Forwarded-For deny all?

request_header_access From deny all?

request_header_access Via deny all

follow_x_forwarded_for deny all

request_header_access Referer deny all

request_header_access User-Agent deny all

cache_peer 115.213.238.102 parent 35759 0 no-query weighted-round-robin weight=1 connect-fail-limit=2 allow-miss max-conn=5 name=115.213.238.10220

never_direct allow all

其中這里就是你可用的http 代理ip列表

cache_peer 115.213.238.102 parent 35759 0 no-query weighted-round-robin weight=1 connect-fail-limit=2 allow-miss max-conn=5 name=115.213.238.10220

網(wǎng)上免費(fèi)的質(zhì)量都不高,有銀子的建議買(mǎi)收費(fèi)的~

如果你使用的是pyspider的話,還可以直接建立一個(gè)任務(wù),定時(shí)爬取某個(gè)免費(fèi)的代理列表。然后通過(guò)任務(wù)定時(shí)生成squid.conf文件。

以下是代碼片段,大家參考一下

先復(fù)制一份squid.conf.example當(dāng)做模板??梢詤⒖既缦麓a:

cd /etc/squid

mv squid.conf.default squid.conf.example

以下是更新conf的代碼:

????????proxy_list = response.json['msg']#獲取到的ip列表

????????default_conf = open('/etc/squid/squid.conf.example' , 'r').read()#讀取模板文件

? ? ? ? default_conf += '\n'

? ? ? ? for index? in range(len(proxy_list)):#把ip定制成指定格式

? ? ? ? ? ? ip, port? = proxy_list[index]['ip'], ?proxy_list[index]['port']

? ? ? ? ? ? proxy_conf = "cache_peer " + ip + " parent " + str(port) + " 0 no-query weighted-round-robin weight=2 connect-fail-limit=2 allow-miss max-conn=5 name=proxy-" + str(index) + "\n"

? ? ? ? ? ? default_conf += proxy_conf

? ? ? ? default_conf += '\n never_direct allow all'

? ? ? ? conf = open('/etc/squid/squid.conf' , 'w')#存儲(chǔ)文件

? ? ? ? conf.write(default_conf)

? ? ? ? conf.close()

? ? ? ? message = os.system('systemctl restart squid')



--------------

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 1 書(shū)籍 http://www.phpfans.net/manu/Squid/ 2 ssl配置 http://zo...
    不排版閱讀 1,217評(píng)論 2 0
  • 常用配置指令說(shuō)明 1. ServerRoot:服務(wù)器的基礎(chǔ)目錄,一般來(lái)說(shuō)它將包含conf/和logs/子目錄,其它...
    小僧有禮了閱讀 4,702評(píng)論 0 5
  • 1.環(huán)境準(zhǔn)備 centos7 1.1、yum安裝設(shè)置 yum list |grep openstackcentos...
    davisgao閱讀 5,672評(píng)論 1 16
  • 安裝squid yum -y install squid 配置 squid 配置文件位置 /etc/squid/s...
    ABasicVersion閱讀 818評(píng)論 0 1
  • NAME dnsmasq - A lightweight DHCP and caching DNS server....
    ximitc閱讀 2,991評(píng)論 0 0

友情鏈接更多精彩內(nèi)容