zoukankan      html  css  js  c++  java
  • 爬取代理IP

     1 #coding=utf-8
     2 import re
     3 import urllib.request
     4 import urllib.parse
     5 import os
     6 from urllib.error import URLError,HTTPError
     7 url='http://www.kuaidaili.com/ops/' #http://www.xicidaili.com/  http://www.proxy360.cn/default.aspx  http://www.kuaidaili.com/ops/
     8 headers={'Accept':'text/html,application/xhtml+xm…plication/xml;q=0.9,*/*;q=0.8',
     9          'Accept-Encoding':'gzip,deflate',
    10          'Accept-Language':'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
    11          'Host':'fs.xicidaili.com',
    12          'Cookie':'Hm_lvt_0cf76c77469e965d2957f0553e6ecf59=1511441689,1511784134,1511785760; Hm_lpvt_0cf76c77469e965d2957f0553e6ecf59=1511785760',
    13          'Connection':'keep-alive',
    14          'User-Agent':'Mozilla/5.0 (Windows NT 6.1; W…) Gecko/20100101 Firefox/57.0'
    15 }
    16 headers=urllib.parse.urlencode(headers).encode('utf8')
    17 rep=urllib.request.Request(url,headers)
    18 reponse=urllib.request.urlopen(rep)
    19 html=reponse.read().decode(encoding='UTF-8')
    20 reg=r'(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'
    21 ip_list=re.findall(reg,html)
    22 print(ip_list)
    23 f=open('ip.txt','a')
    24 f.write(str(ip_list)+'
    ')
    25 f.close()

    
    
  • 相关阅读:
    作业二
    作业一
    作业十一
    作业十
    作业九
    作业八
    作业七
    作业六
    作业五
    JAVA第三次作业
  • 原文地址:https://www.cnblogs.com/brogong/p/7929429.html
Copyright © 2011-2022 走看看