#-*- coding:UTF:8-*- #author:若鳥 #date;2017-1-3 #function:爬取代理IP及其端口,並將其存入一個列表中,返回一個代理IP池 ''' ''' import urllib.request import re def _get_Proxy_IP(): header={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0"} #模擬瀏覽器登錄 url = 'http://www.xicidaili.com/' seq=urllib.request.Request(url,headers=header) response = urllib.request.urlopen(seq) html = response.read().decode("utf-8") print(html) IP = re.findall(r'<td>(\d.+\.\d.+)</td>',html) #正則表達式匹配IP,139.208.74.56 PORT = re.findall(r'<td>(\d{2,4})</td>',html) #正則匹配端口,沒能思考出和IP地址一起匹配的方法,以後增加 Proxy_IP=[] for i in range(0,len(IP)): Proxy_IP.append(IP[i]+":"+PORT[i]) print(Proxy_IP) return Proxy_IP
爬取免費IP代理,以列表形式返回
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.