forked from sosoho/my-python-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsave_memcache.py
More file actions
47 lines (41 loc) · 1.17 KB
/
save_memcache.py
File metadata and controls
47 lines (41 loc) · 1.17 KB
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
#!/bin/env python
# -*- coding:utf-8 -*-
# _author:kaliarch
import memcache
import random
import configparser
import spider
class MemcacheOper:
def __init__(self):
"""
initialization redis infomation
:param
"""
config = configparser.ConfigParser()
config.read('db.conf')
self.host = config['memcache']['HOST']
self.port = config['memcache']['PORT']
self.mcoper = memcache.Client([self.host+':'+self.port], debug = True)
def memcache_save(self,result_list):
"""
save data
:return:None
"""
for num,cont in enumerate(result_list):
self.mcoper.set(str(num),cont)
def memcache_gain(self):
"""
gain data
:return: proxies
"""
num = random.randint(0,10)
ip = self.mcoper.get(str(num))
return ip
if __name__ == '__main__':
proxyhelper = spider.GetProxyIP(2)
res_pool = proxyhelper.get_ip()
proxy_ip = proxyhelper.right_proxies(res_pool)
dbhelper = MemcacheOper()
dbhelper.memcache_save(proxy_ip)
ip = dbhelper.memcache_gain()
print(ip)