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))
如何快速捕獲網頁的IP地址
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.