代理IP抓取

  • 2020 年 11 月 03 日
  • 60次
  • 6 字
  • 暂无评论

示例链接:http://www.nimadaili.com/gaoni/

import urllib.request,re,time
def abc(id):
    url = "http://www.nimadaili.com/gaoni/"+ str(id) +"/"
    response = urllib.request.urlopen(url)
    data = response.read().decode("utf-8")
    datas = data.replace('\n', '').replace('\r', '').replace(' ', '')
    # print(datas)
    pat = r"</td></tr><tr><td>(.*?)</td><td>"
    re_joke = re.compile(pat, re.S)
    idList = re_joke.findall(datas)
    print(idList)
    ipS = ""
    for i in idList:
        ipS += i + '\n'

    path = r"C:\Users\Administrator\Desktop\ips.txt"
    with open(path,"a") as f:
        f.write(ipS)
for num in range(1,90):
    print("第:" + str(num) + "页")
    abc(num)
    time.sleep(5)

版权属于:RA

本文链接:https://rablog.top/3.html

本站分享的所有资源,均不得用于非法用途!



—— 暂无评论 ——

OωO