MCPcopy Create free account
hub / github.com/awolfly9/IPProxyTool / Validator

Class Validator

crawler/spiders/validator/validator.py:13–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11
12
13class Validator(Spider):
14 name = 'base'
15 concurrent_requests = 16
16 retry_enabled = False
17
18 def __init__(self, name = None, **kwargs):
19 super(Validator, self).__init__(name, **kwargs)
20
21 self.urls = []
22 self.headers = None
23 self.timeout = 10
24 self.success_status = [200]
25 self.is_record_web_page = False
26
27 self.sql = SqlManager()
28
29 def init(self):
30 self.dir_log = 'log/validator/%s' % self.name
31 utils.make_dir(self.dir_log)
32
33 self.sql.init_proxy_table(self.name)
34
35 @classmethod
36 def update_settings(cls, settings):
37 settings.setdict(cls.custom_settings or {
38 'CONCURRENT_REQUESTS': cls.concurrent_requests,
39 'RETRY_ENABLED': cls.retry_enabled,
40 },
41 priority = 'spider')
42
43 def start_requests(self):
44 count = self.sql.get_proxy_count(self.name)
45 count_free = self.sql.get_proxy_count(config.httpbin_table)
46
47 ids = self.sql.get_proxy_ids(self.name)
48 ids_httpbin = self.sql.get_proxy_ids(config.httpbin_table)
49
50 for i in range(0, count + count_free):
51 table = self.name if (i < count) else config.httpbin_table
52 id = ids[i] if i < count else ids_httpbin[i - len(ids)]
53
54 proxy = self.sql.get_proxy_with_id(table, id)
55 if proxy == None:
56 continue
57
58 url = random.choice(self.urls)
59 cur_time = time.time()
60 yield Request(
61 url = url,
62 headers = self.headers,
63 meta = {
64 'cur_time': cur_time,
65 'download_timeout': self.timeout,
66 'proxy_info': proxy,
67 'table': table,
68 'proxy': 'http://%s:%s' % (proxy.ip, proxy.port),
69 },
70 dont_filter = True,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected