1. 程式人生 > >WEB - 定時獲取代理池(簡單方法)

WEB - 定時獲取代理池(簡單方法)

quest 循環 定時 def int urn 腳本 time 獲取

import requests
import time
from read_ip_pool import read_ip_pool

PROXIES_URL = ‘‘


def get_ip_pool(url=PROXIES_URL):
    """ 根據URL構造代理池

    :param PROXIES_URL:
    :return: []
    """
    response = requests.get(url)
    with open(‘IP_POOL‘, ‘w‘) as f:
        f.write(response.text)
    print(‘get_ip_pool is done‘)

# Unix, 後臺運行腳本: <script_name> &
while True:
    get_ip_pool()
    read_ip_pool()
    # time+死循環, 實現定時功能。
    time.sleep(10)
    print("")

WEB - 定時獲取代理池(簡單方法)