我目前正在使用osmosis
抓取各种帐户中的信息。为了登录这些帐户,我尝试使用submit
命令。但是,它似乎没有任何作用。我也尝试过.login
,但这似乎根本无法识别表格。
文档似乎缺少任何示例。有人使用.submit
来体验osmosis
吗?
osmosis
.get(url)
.submit("form", {'gebruikersnaam': username, 'wachtwoord': password})
.log(console.log)
.error(console.log)
.debug(console.log);
答案 0 :(得分:0)
它因网站而异。我假设您尝试登录的网站正在使用某种Ajax。如果.submit
无法解决问题,您可以尝试执行.post
。这是解决方法示例。尝试看看是否可行。
.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。