HCE Project Python language Distributed Tasks Manager Application, Distributed Crawler Application and client API bindings.  2.0.0-chaika
Hierarchical Cluster Engine Python language binding
ftest_HTTPCookieResolver.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 # coding: utf-8
3 
4 import os
5 import sys
6 import logging
7 from dc_crawler.HTTPCookieResolver import HTTPCookieResolver
8 from app.Utils import varDump
9 from app.Utils import parseHost
10 import app.Consts as APP_CONSTS
11 
12 
13 def getLogger():
14  # create logger
15  logger = logging.getLogger(APP_CONSTS.LOGGER_NAME)
16  logger.setLevel(logging.DEBUG)
17 
18  # create console handler and set level to debug
19  ch = logging.StreamHandler()
20  ch.setLevel(logging.DEBUG)
21 
22  # create formatter
23  formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
24 
25  # add formatter to ch
26  ch.setFormatter(formatter)
27 
28  # add ch to logger
29  logger.addHandler(ch)
30 
31  return logger
32 
33 
34 if __name__ == '__main__':
35 
36  logger = getLogger()
37 
38  # testUrl = 'http://www.nytimes.com/pages/realestate/index.html'
39  # testUrl = 'http://mainichi.jp/auth/check_cookie_set.php?url=%2Farticles%2F20161101%2Fdde%2F041%2F200%2F060000c'
40  testUrl = 'http://thecaucus.blogs.nytimes.com/feed'
41  # testCookie = 'RMID=007f010001ef57ecce0c0044; Expires=Fri, 29 Sep 2017 08:17:16 GMT; Path=/; Domain=.nytimes.com;, adxcs=-; path=/; domain=.nytimes.com'
42  # testCookie = 'nyt-a=404c415521b8f3e8d92e2623d60ed4af;path=/;domain=.nytimes.com;expires=Fri, 29 Sep 2017 08:16:31 UTC, RMID=007f010116a357eccddf000a;path=/;domain=.nytimes.com;expires=Fri, 29 Sep 2017 08:16:31 UTC'
43  # testCookie = 'AWSELB=2D635D7F085943AF3ED70A1AE907E156AF95FD853A1E9DE41257D736BB0878FA62AACDB3328FCEE98FCA65B7ACC78DD533A33CA7252F22C4169A8EDB2A037EDCE533C6706E;PATH=/;MAX-AGE=3600'
44  # testCookie = 'ckcheck=20161101203738; path=/; domain=.mainichi.jp, ck=1; path=/; domain=.mainichi.jp'
45  # testCookie = 'PHPSESSID=dmk9qv40ejptcf34n5005895o6; path=/; domain=.mainichi.jp, PHPSESSID=dmk9qv40ejptcf34n5005895o6; path=/; domain=.mainichi.jp, PHPSESSID=ri3eoe3tfn4jkhutb0l45f2an3; path=/; domain=.mainichi.jp, PHPSESSID=ri3eoe3tfn4jkhutb0l45f2an3; path=/; domain=.mainichi.jp'
46  # testCookie = 'NYT-S=0MzycNAz.DKnTDXrmvxADeHw9CANpeHfgkdeFz9JchiAIUFL2BEX5FWcV.Ynx4rkFI; expires=Fri, 02-Dec-2016 08:13:55 GMT; path=/; domain=.nytimes.com, NYT-BCET=1480666435%7CUD9ePFkvdXpfhpUrb1QP%2FzMtX0g%3D%7C4AKhntb6qrGHHvrp1CH2J0vL000x7RbLgKUF%2BQ2nJYs%3D; expires=Mon, 01-May-2017 08:13:55 GMT; path=/; domain=.nytimes.com; httponly'
47  testCookie = '2e207a62fe17ce9f8bbbb86a50498c41=nk8srbd1hsmia5j9mf7to6oj80\r\nja_t3_blank_tpl; '
48  # testJSON = "{\"nytimes.com\":{\"stage\":4, \"cookie\":\"12345\"}}"
49  # testJSON = "{\"nytimes.com\":{\"stage\":4}}"
50  testJSON = "{\"%s\":{\"stage\":4}}" % (parseHost(testUrl))
51 
52 
53  cookieResolver = HTTPCookieResolver(testJSON)
54  cookieResolver.addCookie(testUrl, testCookie)
55  cookie = cookieResolver.getCookie(testUrl)
56  logger.debug('cookie: ' + str(cookie))
57 
def parseHost(url)
Definition: Utils.py:947