【问题标题】:Node JS - Osmosis form .submitNode JS - Osmosis 表单 .submit
【发布时间】:2018-10-23 13:45:03
【问题描述】:

我目前正在使用osmosis 来抓取各种帐户中的信息。为了登录这些帐户,我尝试使用submit 命令。然而,它似乎没有做任何事情。我也尝试过.login,但这似乎根本无法识别表单。

文档似乎缺少任何示例。有人使用osmosis 体验过.submit 吗?

osmosis
    .get(url)
    .submit("form", {'gebruikersnaam': username, 'wachtwoord': password})
    .log(console.log)
    .error(console.log)
    .debug(console.log);

【问题讨论】:

    标签: node.js osmosis


    【解决方案1】:

    它因网站而异。我假设您尝试登录的网站正在使用某种 ajax。如果.submit 没有成功,你可以尝试做.post。这是解决方法示例。试试看是否有效。

    1. 通过登录后获取 cookie。第一个渗透实例
    2. 在第二个渗透实例中设置.config中的cookie

    代码:

    osmosis
    .get(loginUrl)
    .post(loginPosturlTarget, {'username': username, 'password': password})
    .then((context)=>{
        // store cookies after post login.
        let cookies = cookie.parse(context.request.headers['cookie']);
        scrapeData(cookies);
    
    })
    .log(console.log)
    .error(console.log)
    .debug(console.log);
    
    function scrapeData(cookies){
        // do the actual scraping here with the cookie here
        osmosis
        .config('cookies', cookies)
        .get(url) 
        // your follow/set/paginate/whatever chain here
        .data((data)=> {
            // do something with the data
        })
        .log(console.log)
        .error(console.log)
        .debug(console.log);
    }
    

    它不能保证在你的情况下工作,但我发现这在我工作过的大多数网站上都有效。如果还是不行,不妨试试nightmareJs等其他替代模块。

    【讨论】:

      猜你喜欢
      • 2021-10-23
      • 2012-12-15
      • 1970-01-01
      • 1970-01-01
      • 2014-11-11
      • 1970-01-01
      • 1970-01-01
      • 2018-11-07
      • 1970-01-01
      相关资源
      最近更新 更多