forked from sosoho/my-python-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsave_mongodb.py
More file actions
59 lines (49 loc) · 1.48 KB
/
save_mongodb.py
File metadata and controls
59 lines (49 loc) · 1.48 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
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/env python
# -*- coding:utf-8 -*-
# _author:kaliarch
#!/bin/env python
# -*- coding:utf-8 -*-
# _author:kaliarch
import configparser
import spider
from pymongo import MongoClient
class MongodbOper:
def __init__(self):
"""
initialization redis infomation
:param
"""
config = configparser.ConfigParser()
config.read('db.conf')
self.host = config['mongodb']['HOST']
self.port = config['mongodb']['PORT']
self.db = config['mongodb']['DB']
self.user = config['mongodb']['USER']
self.pwd = config['mongodb']['PASSWD']
self.client = MongoClient(self.host, int(self.port))
self.db_auth = self.client.admin
self.db_auth.authenticate(self.user,self.pwd)
self.DB = self.client[self.db]
self.collection = self.DB.myset
def mongodb_save(self,result_list):
"""
save data
:return:None
"""
for values in result_list:
self.collection.insert(values)
def mongodb_gain(self):
"""
gain data
:return: proxies
"""
ip = self.collection.find_one()
return ip
if __name__ == '__main__':
proxyhelper = spider.GetProxyIP(2)
res_pool = proxyhelper.get_ip()
proxy_ip = proxyhelper.right_proxies(res_pool)
dbhelper = MongodbOper()
dbhelper.mongodb_save(proxy_ip)
ip = dbhelper.mongodb_gain()
print(ip)