使用redis統計ip的使用次數
count_ip_key='spider_ip'
ip_limit_num = 500
def count_ip(ip): #統計ip次數
count = r.hget(count_ip_key,ip)
if isinstance(count,bytes):r.hset(count_ip_key,ip, eval(count)+1)
else:r.hset(count_ip_key,ip, 1)
def num_ip(ip): 獲取ip的次數與限制值比較
count = r1.hget(count_ip_key, ip)
if isinstance(count,bytes):return eval(count)
else:return 0
while True:
if r.scard(proxy_key) > 0:
ip = r.spop(proxy_key)
if not isinstance(ip,bytes):continue
ip=ip.decode()
print('ip:',ip)
if num_ip(ip) > ip_limit_num:
continue
proxies = {'http': 'http://{}'.format(ip), 'https': 'http://{}'.format(ip)}
爬蟲函式
count_ip(ip)
if num_ip(ip) < ip_limit_num:
r.sadd(proxy_key,ip)
相關文章
- redis實現統計使用者連續登陸天數Redis
- redis設計統計使用者訪問量Redis
- 在SpringBoot中使用Redis的zset統計線上使用者資訊Spring BootRedis
- 如何用 Redis 統計使用者訪問量?Redis
- 記一次 Laravel 使用 Redis 踩得坑LaravelRedis
- Redis的使用Redis
- JavaScript統計字元出現的次數JavaScript字元
- 統計字串出現的次數(C)字串
- 使用 Redis 有序集合實現 IP 歸屬地查詢Redis
- nginx 使用同事的IPNginx
- 使用代理ip的原因
- matlab——統計相同元素出現的次數Matlab
- 用Python統計次數的5種方法Python
- Redis的使用(二)Redis
- laravel 單使用者 單IP 頻次訪問限制Laravel
- Redis pipeline 在連續一萬次插入操作測試中的使用Redis
- 統計檔案中出現的單詞次數
- Redis在.net中的使用(2).net專案中的Redis使用Redis
- 代理ip的授權使用
- Redis 點陣圖基礎到統計活躍使用者Redis
- 統計陣列中各數字(元素)出現的次數陣列
- 使用redis中setnx防止併發二次寫入Redis
- MongoDB和Redis的使用MongoDBRedis
- 使用 CSS 計數器CSS
- Linux中如何使用Sipcalc計算IP子網LinuxPCA
- (7)ram ip使用
- 隧道代理ip使用
- 使用者日活月活怎麼統計 - Redis HyperLogLog 詳解Redis
- Matlab 統計陣列中各數字(元素)出現的次數Matlab陣列
- IP類介面大全,含免費次數
- 爬蟲代理IP的使用技巧爬蟲
- Laravel 使用 RedisLaravelRedis
- SpringBoot使用RedisSpring BootRedis
- PHP使用redisPHPRedis
- Redis基本使用Redis
- Lumen使用RedisRedis
- Oracle統計某個使用者下所有表的各自行數Oracle
- awk統計訪問nginx日誌次數Nginx