Module pywander.crawler.js_file_loader

javascript文件硬分析来获取必要的信息

Functions

def js_file_loader(text)
Expand source code
def js_file_loader(text):
    data = {}
    text = remove_javascript_comment(text)
    text = remove_javascript_semicolon(text)
    data = parse_var_definition(text)
    data = load_pyvalue(data)
    return data
def load_pyvalue(data)
Expand source code
def load_pyvalue(data):
    new_data = {}
    for key,value in data.items():
        py_value = json.loads(value)
        new_data[key] = py_value

    return new_data
def parse_var_definition(text)
Expand source code
def parse_var_definition(text):
    data = {}
    for t, _, _ in pp_var_definition.scan_string(text):
        var_name = t.name
        var_value = t.value
        data[var_name] = var_value

    return data
def pp_action_remove(tokens)
Expand source code
def pp_action_remove(tokens):
    return ''
def pp_action_remove_semicolon(tokens)
Expand source code
def pp_action_remove_semicolon(tokens):
    return '\n'
def remove_javascript_comment(text)
Expand source code
def remove_javascript_comment(text):
    """
    移除javascript中的注释
    """
    text = pp_remove_javascript_comment.transform_string(text)
    return text

移除javascript中的注释

def remove_javascript_semicolon(text)
Expand source code
def remove_javascript_semicolon(text):
    """
    方便后续处理,将分号转成换行
    """
    text = pp_semicolon.set_parse_action(pp_action_remove_semicolon).transform_string(text)
    return text

方便后续处理,将分号转成换行