ProxyPool 爬?代理IP池 ______ ______ _ | ___ \_ | ___ \ | | | |_/ / \__ __ __ _ __ _ | |_/ /___ ___ | | | __/| _// _ \ \ \/ /| | | || __// _ \ / _ \ | | | | | | | (_) | > < \ |_| || | | (_) | (_) || |___ \_| |_| \___/ /_/\_\ \__ |\_| \___/ \___/ \_____\ __ / / /___ / ProxyPool 爬?代理IP池?目,主要功能?定?采集?上?布的免?代理??入?,定???入?的代理保?代理的可用性,提供API和CLI??使用方式。同??也可以?展代理源以增加代理池IP的?量和?量。 文?: document 支持版本: ??地址: http://demo.spiderpy.cn (勿???) 付?代理推?: luminati-china . ?外的亮?据BrightData(以前叫luminati)被??是代理市???者,覆盖全球的7200万IP,大部分是?人住宅IP,成功率??的。付?套餐多?,需要高?量代理IP的可以注?后?系中文客服,?通后?送5美金余?和?程指引(PS:用不明白的同?可以?考?? 使用?程 )。 ?行?目 下?代?: git clone git clone git@github.com:jhao104/proxy_pool.git releases https://github.com/jhao104/proxy_pool/releases 下???zip文件 安?依?: pip install -r requirements.txt 更新配置: # setting.py ??目配置文件 # 配置API服? HOST = "0.0.0.0" # IP PORT = 5000 # ??端口 # 配置?据? DB_CONN = 'redis://:pwd@127.0.0.1:8888/0' # 配置 ProxyFetcher PROXY_FETCHER = [ "freeProxy01" , # ?里是?用的代理?取方法名,所有fetch方法位于fetcher/proxyFetcher.py "freeProxy02" , # .... ] ???目: # 如果已?具??行?件, 可用通?proxyPool.py??。 # 程序分?: schedule ?度程序 和 server Api服? # ???度程序 python proxyPool.py schedule # ??webApi服? python proxyPool.py server Docker Image docker pull jhao104/proxy_pool docker run --env DB_CONN=redis://:password@ip:port/0 -p 5010:5010 jhao104/proxy_pool:latest docker-compose ?目目?下?行: docker-compose up -d 使用 Api ??web服?后, 默?配置下??? http://127.0.0.1:5010 的api接口服?: api method Description params / GET api介? None /get GET ?机?取一?代理 可???: ?type=https ??支持https的代理 /pop GET ?取??除一?代理 可???: ?type=https ??支持https的代理 /all GET ?取所有代理 可???: ?type=https ??支持https的代理 /count GET ?看代理?量 None /delete GET ?除代理 ?proxy=host:ip 爬?使用 如果要在爬?代?中使用的?, 可以?此api封?成函?直接使用,例如: import requests def get_proxy (): return requests . get ( "http://127.0.0.1:5010/get/" ). json () def delete_proxy ( proxy ): requests . get ( "http://127.0.0.1:5010/delete/?proxy={}" . format ( proxy )) # your spider code def getHtml (): # .... retry_count = 5 proxy = get_proxy (). get ( "proxy" ) while retry_count > 0 : try : html = requests . get ( 'http://www.example.com' , proxies = { "http" : "http://{}" . format ( proxy )}) # 使用代理?? return html except Exception : retry_count -= 1 # ?除代理池中代理 delete_proxy ( proxy ) return None ?展代理 ?目默?包含??免?的代理?取源,但是免?的?竟?量有限,所以如果直接?行可能拿到的代理?量不理想。所以,提供了代理?取的?展方法。 添加一?新的代理源方法如下: 1、首先在 ProxyFetcher ?中添加自定?的?取代理的??方法, ?方法需要以生成器(yield)形式返回 host:ip 格式的代理,例如: class ProxyFetcher ( object ): # .... # 自定?代理源?取方法 @ staticmethod def freeProxyCustom1 (): # 命名不和已有重??可 # 通?某?站或者某接口或某?据??取代理 # 假??已?拿到了一?代理列表 proxies = [ "x.x.x.x:3128" , "x.x.x.x:80" ] for proxy in proxies : yield proxy # ?保每?proxy都是 host:ip正?的格式返回 2、添加好方法后,修改 setting.py 文件中的 PROXY_FETCHER ?: 在 PROXY_FETCHER 下添加自定?方法的名字: PROXY_FETCHER = [ "freeProxy01" , "freeProxy02" , # .... "freeProxyCustom1" # # ?保名字和?添加方法名字一致 ] schedule ?程?每隔一段???取一次代理,下次?取??自????用?定?的方法。 免?代理源 目前??的采集免?代理?站有(排名不分先后, 下面?是?其?布的免?代理情?, 付?代理??可以?考 ?里 ): 代理名? ?? 更新速度 可用率 地址 代? 站大? ? ★ ** 地址 freeProxy01 66代理 ? ★ * 地址 freeProxy02 ?心代理 ? ★ * 地址 freeProxy03 FreeProxyList ? ★ * 地址 freeProxy04 快代理 ? ★ * 地址 freeProxy05 ?凌代理 ? ★★★ * 地址 freeProxy06 云代理 ? ★ * 地址 freeProxy07 小幻代理 ? ★★ * 地址 freeProxy08 免?代理? ? ☆ * 地址 freeProxy09 89代理 ? ☆ * 地址 freeProxy10 稻?代理 ? ★★ *** 地址 freeProxy11 如果?有其他好的免?代理?站, 可以在提交在 issues , 下次更新??考?在?目中支持。 ??反? 任何???迎在 Issues 中反?,同?也可以到我的 博客 中留言。 ?的反???此?目?得更加完美。 ??代? 本?目?作?基本的通用的代理池架?,不接收特有功能(?然,不限于特?好的idea)。 本?目依然不?完善,如果??bug或有新的功能添加,?在 Issues 中提交bug(或新功能)描述,我??力改?,使?更加完美。 ?里感?以下contributor的无私奉?: @kangnwh | @bobobo80 | @halleywj | @newlyedward | @wang-ye | @gladmo | @bernieyangmh | @PythonYXY | @zuijiawoniu | @netAir | @scil | @tangrela | @highroom | @luocaodan | @vc5 | @1again | @obaiyan | @zsbh | @jiannanya | @Jerry12228 Release Notes changelog