如何快速捕获网页的IP地址

import re,os
import urllib.request

def open_url(url):
    req = urllib.request.Request(url)
    req.add_header('User-Agent','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36 X-Requested-With: XMLHttpRequest')
    response = urllib.request.urlopen(req)
    html = response.read().decode('utf-8')
    return html

def get_img(html):
    p = r'(?:(?:[01]?\d?\d|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d?\d|2[0-4]\d|25[0-5])'  #注意?:让子组不捕获组内容
    iplist = re.findall(p,html)
    for ip in iplist:
        print(ip)

    # for each in imglist:
    #     filename = each.split('/')[-1]
    #     urllib.request.urlretrieve(each,filename,None)

if __name__ == "__main__":
    url = "https://www.xicidaili.com/nt/"
    get_img(open_url(url))
发布了71 篇原创文章 · 获赞 3 · 访问量 1万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览