Esempio n. 1
0
 def parse_share_page(content):
     tree = html.fromstring(content)
     script_sel = CSS("script")
     scripts = script_sel(tree)
     for script in scripts:
         if script.text and (
             script.text.find("viewsingle_param") > -1 or script.text.find("mpan.viewlist_param") > -1
         ):
             break
     else:
         logger.warn("pcs.parse_share_page: failed to get filelist, %s", url)
         return None
     start = script.text.find("viewsingle_param.list=JSON.parse(")
     end = script.text.find(");mpan.viewsingle_param.username")
     if start == -1 or end == -1:
         start = script.text.find("listArr:JSON.parse(")
         end = script.text.find("),rootPath:")
         if start == -1 or end == -1:
             return None
         else:
             json_str = script.text[start + 19 : end]
     else:
         json_str = script.text[start + 33 : end]
     try:
         return json.loads(json.loads(json_str))
     except ValueError:
         logger.warn(traceback.format_exc())
         return None
Esempio n. 2
0
 def parse_share_page(content):
     tree = html.fromstring(content)
     script_sel = CSS('script')
     scripts = script_sel(tree)
     for script in scripts:
         if (script.text
                 and (script.text.find('viewsingle_param') > -1
                      or script.text.find('mpan.viewlist_param') > -1)):
             break
     else:
         logger.warn('pcs.parse_share_page: failed to get filelist, %s',
                     url)
         return None
     start = script.text.find('viewsingle_param.list=JSON.parse(')
     end = script.text.find(');mpan.viewsingle_param.username')
     if start == -1 or end == -1:
         start = script.text.find('listArr:JSON.parse(')
         end = script.text.find('),rootPath:')
         if start == -1 or end == -1:
             return None
         else:
             json_str = script.text[start + 19:end]
     else:
         json_str = script.text[start + 33:end]
     try:
         return json.loads(json.loads(json_str))
     except ValueError:
         logger.warn(traceback.format_exc())
         return None
Esempio n. 3
0
def get_user_uk(cookie, tokens):
    """获取用户的uk"""
    url = "http://yun.baidu.com"
    req = net.urlopen(url, headers={"Cookie": cookie.header_output()})
    if req:
        content = req.data.decode()
        match = re.findall('/share/home\?uk=(\d+)" target=', content)
        if len(match) == 1:
            return match[0]
        else:
            logger.warn("pcs.get_user_uk(), failed to parse uk, %s" % url)
    return None
Esempio n. 4
0
def get_user_uk(cookie, tokens):
    '''获取用户的uk'''
    url = 'http://yun.baidu.com'
    req = net.urlopen(url, headers={'Cookie': cookie.header_output()})
    if req:
        content = req.data.decode()
        match = re.findall('/share/home\?uk=(\d+)" target=', content)
        if len(match) == 1:
            return match[0]
        else:
            logger.warn('pcs.get_user_uk(), failed to parse uk, %s' % url)
    return None