首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Jint编辑.js

使用Jint编辑.js
EN

Stack Overflow用户
提问于 2021-09-02 00:50:14
回答 1查看 67关注 0票数 0

我正在尝试用jint编辑下面的javascript。我真的只想在运行时在defaultConfig中编辑var antiCapthaPredefinedApiKey = '';和设置代理设置。我有一个winforms,我将把这两个值传递给我调用的方法来编辑它。这是js,

代码语言:javascript
复制
// Public config

var antiCapthaPredefinedApiKey = '';

var defaultConfig = {
    // settings
    enable: true,
    account_key: antiCapthaPredefinedApiKey,
    auto_submit_form: true,
    play_sounds: false,
    delay_onready_callback: false,

    where_solve_list: [], // i.e. ['example.com', 'www.ladysproblems.com']
    where_solve_white_list_type: false, // true -- considered as white list, false -- black list

    solve_recaptcha2: true,
    solve_recaptcha3: true,
    recaptcha3_score: 0.3,
    solve_invisible_recaptcha: true,
    solve_funcaptcha: true,
    solve_geetest: true,
    solve_hcaptcha: true,
    use_predefined_image_captcha_marks: true,

    solve_proxy_on_tasks: false,
    user_proxy_protocol: 'HTTP',
    user_proxy_server: '',
    user_proxy_port: '',
    user_proxy_login: '',
    user_proxy_password: '',

    use_recaptcha_precaching: false,
    k_precached_solution_count_min: 2,
    k_precached_solution_count_max: 4,

    dont_reuse_recaptcha_solution: true,
    start_recaptcha2_solving_when_challenge_shown: false,
    solve_only_presented_recaptcha2: false,

    // use_recaptcha_accelerator: false,

    // status
    account_key_checked: antiCapthaPredefinedApiKey ? true : false, // set after account_key check
    free_attempts_left_count: 15 // move to config
};

这是我当前执行的代码,但它并没有改变我所知道的变量。我也没有先添加编辑代理设置,因为我想看看是否可以更改api密钥变量。一旦完成,我只想保存文件。这是我第一次使用jint,所以我对它缺乏经验。

代码语言:javascript
复制
        public static void ReadJsFile(string api, string proxy)
        {
            string workingDirectory1 = Environment.CurrentDirectory;
            string filePath = workingDirectory1 + "\\anticaptcha\\js\\config_ac_api_key.js";

            var engine = new Engine();

            var antiCap = File.ReadAllText(filePath);
            engine.Execute(antiCap);

            engine.SetValue("antiCapthaPredefinedApiKey", api);      
        }
EN

回答 1

Stack Overflow用户

发布于 2021-09-03 15:35:04

在执行engine.Execute(antiCap)行之后,已经对defaultConfig求值,并在求值时用antiCapthaPredefinedApiKey的值填充,该值是一个空字符串。之后更改antiCapthaPredefinedApiKey的值不会影响defaultConfig

要获得您想要的内容,请不要在JS文件中定义antiCapthaPredefinedApiKey,并在执行脚本之前使用Jint设置其值:

代码语言:javascript
复制
public static void ReadJsFile(string api, string proxy)
{
    string workingDirectory1 = Environment.CurrentDirectory;
    string filePath = workingDirectory1 + "\\anticaptcha\\js\\config_ac_api_key.js";
    var engine = new Engine();
    var antiCap= File.ReadAllText(filePath);
    engine.SetValue("antiCapthaPredefinedApiKey", api);
    engine.Execute(antiCap);
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69022866

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档