国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

腳本之家,腳本語言編程技術及教程分享平臺!
分類導航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務器之家 - 腳本之家 - Python - Python采集代理ip并判斷是否可用和定時更新的方法

Python采集代理ip并判斷是否可用和定時更新的方法

2021-02-18 00:46lilongsy Python

今天小編就為大家分享一篇Python采集代理ip并判斷是否可用和定時更新的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

網上有很多免費的ip地址,都是可以使用的,但是如果手動來獲取太麻煩,這里通過Python自動抓取,可以批量獲取。

代碼如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# -*- coding: utf-8 -*-
import re
import urllib2
import json
import os
import time
import socket
 
class ProxyIp(object):
  def __init__(self):
    self.path = os.path.split(os.path.realpath(__file__))[0]
  # Get latest proxy ip and download to json
  def update_ip(self):
    print 'Update Ip'
    url = 'http://www.ip3366.net/free/'
    req = urllib2.Request(url)
    response = urllib2.urlopen(req)
    matches = re.findall(
      ur'(\d+.\d+.\d+.\d+)</td>\s+<td>(\d+)</td>\s+<td>.*?</td>\s+<td>(HTTPS?)</td>',
      response.read(),
      re.I
    )
    ls = []
    for match in matches:
      if self.is_open(match[0], match[1]):
        ls.append({'ip':match[0], 'port':match[1], 'protocol': match[2]})
    with open('%s/ip.json' % self.path, 'w') as f:
      json.dump(ls, f)
    return ls
  # whether the ips is last or old.
  def is_last(self):
    m_time = int(os.path.getmtime('%s/ip.json' % self.path))
    now_time = int(time.time())
    return (now_time - m_time) > 60*60*4 # 4 hours
  @staticmethod
  def is_open(ip, port):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try:
      s.connect(ip, int(port))
      return True
    except:
      print 'Faild IP: %s:%s' % (ip, port)
      return False
  def get_proxy_ips(self):
    if not self.is_last():
      return self.update_ip()
    else:
      with open('%s/ip.json' % self.path, 'r') as f:
        return json.load(f)

以上這篇Python采集代理ip并判斷是否可用和定時更新的方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持服務器之家。

原文鏈接:https://blog.csdn.net/lilongsy/article/details/76034209

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 黄色视屏在线免费观看 | 中文字幕在线一区二区三区 | 亚洲va | 亚洲在线视频一区二区 | 天天操天天干天天插 | 午夜成人免费电影 | 亚洲社区在线 | 毛片免费观看视频 | 亚洲综合色成在线播放 | 中文字幕 日韩有码 | 欧美在线一区二区 | 伊人激情影院 | 亚洲乱码国产乱码精品精98午夜 | 亚洲精品一区二区三区 | 97操视频 | 日日麻批免费视频40分钟 | 午夜午夜精品一区二区三区文 | 亚洲午夜激情 | 精品久久久久久亚洲综合网 | 亚洲在线视频一区 | 日本亚洲欧美 | 成人午夜毛片 | 亚洲精品日韩在线 | 动漫精品一区二区 | 日韩电影网站 | 黄色毛片免费看 | 国产成人精品久久 | 久久久亚洲国产天美传媒修理工 | 伊人青青草 | 日韩色区 | 综合久久精品 | 久久综合2019 | 亚洲国产aⅴ精品一区二区 少妇一级片免费看 | 777色狠狠一区二区三区 | 天天天操 | 欧美精品一区在线 | 免费中文字幕 | 欧美a在线 | 四虎影视最新免费版 | 涩涩999| 亚洲精品久久久久久久久久久久久 |