python爬取国内代理ip_Python语言爬取代理IP
本文主要向大家介紹了Python語言爬取代理IP,通過具體的內容向大家展示,希望對大家學習Python語言有所幫助。
#!/usr/bin/env python
#-*-coding=utf-8 -*-
#AUTHOR:duwentao
import requests
import re
i = input("請輸入你要爬取第幾頁:")
url = "https://www.kuaidaili.com/free/inha/" + i +"/"
print("獲取代理IP地址")
header = {
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/49.0.2623.221 Safari/537.36 SE 2.X MetaSr
1.0"
}
reponse = requests.get(url,header)
reponse.encoding='utf-8'
html = reponse.text
#p
= r'
(.*?)data-title="PORT">(.*?)
data-title="匿名度">(.*?)
data-title="類型">(.*?)
data-title="位置">(.*?)
data-title="響應速度">(.*?)
data-title="最后驗證時間">(.*?)
'ip = r'
(.*?)'IP = re.findall(ip,html,re.M|re.S)
dk = r'
(.*?)'DK = re.findall(dk,html,re.M|re.S)
f=open("ip_list.txt","a")
for ip in IP:
IP_LIST = ip + ":" + DK[IP.index(ip)] + "\n"
f.write(IP_LIST)
f.close()
print("保存完畢")
本文由職坐標整理并發布,希望對同學們學習Python有所幫助,更多內容請關注職坐標編程語言Python頻道!
總結
以上是生活随笔為你收集整理的python爬取国内代理ip_Python语言爬取代理IP的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 快讯|卡睿智行宣布引入新一轮投资 获欧日
- 下一篇: python asyncio和celer