@@ -0,0 +1,1855 @@
+#!/usr/bin/env python%0A# -*- coding:utf-8 -*-%0A%0A%22%22%22%0AFunctions to get user-agent string%0A%0Ausage:%0Afrom modules.useragent import *%0Astr1 = get_random_agent()%0Astr2 = firefox()%0Astr3 = iphone()%0Astr4 = google_bot()%0A...%0A%0Atips:%0Ainit_UAlist(),get_random_agent()%0Athese 2 methods should be called after %5Bpath-init-method%5D in lib.core.common%0A%22%22%22%0A%0Aimport random%0Afrom lib.core import log%0Afrom lib.core.data import conf, th, paths%0Afrom lib.core.common import getFileItems%0A%0Adef _init_UAlist(path):%0A    # TODO%0A    conf.RANDOM_UA = True%0A    th.UA_LIST = getFileItems(path)%0A%0Adef get_random_agent(path=paths.USER_AGENTS):%0A    if %22UA_LIST%22 not in th:%0A        _init_UAlist(path)%0A    try:%0A        return random.sample(th.UA_LIST, 1)%5B0%5D%0A    except IOError, e:%0A        warnMsg = %22unable to read HTTP User-Agent header %22%0A        warnMsg += %22file '%25s'%22 %25 path%0A        log.warn(warnMsg)%0A        return%0A%0A%0Adef firefox():%0A    return 'Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0'%0A%0A%0Adef ie():%0A    return 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)'%0A%0A%0Adef chrome():%0A    return 'Mozilla/5.0 (Windows NT 5.2) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.122 Safari/534.30'%0A%0A%0Adef opera():%0A    return 'Opera/9.80 (Windows NT 5.1; U; zh-cn) Presto/2.9.168 Version/11.50'%0A%0A%0Adef iphone():%0A    return 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16'%0A%0A%0Adef google_bot():%0A    return 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'%0A%0A%0Adef msn_bot():%0A    return 'msnbot/1.1 (+http://search.msn.com/msnbot.htm)'%0A%0A%0Adef yahoo_bot():%0A    return 'Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)'

add useragent