How to maintain a request session in NodeJS

前端 未结 3 1692
猫巷女王i
猫巷女王i 2020-11-30 21:51

I\'m trying to use NodeJS to scrape a website that requires a login by POST. Then once I\'m logged in I can access a separate webpage by GET<

3条回答
  •  感动是毒
    2020-11-30 21:59

    You need to make a cookie jar and use the same jar for all related requests.

     var cookieJar = request.jar();
     request.post({url : requesturl, jar: cookieJar, form: lform}, ...
    

    That should in theory allow you to scrape pages with GET as a logged-in user, but only once you get the actual login code working. Based on your description of the response to your login POST, that may not be actually working correctly yet, so the cookie jar won't help until you fix the problems in your login code first.

提交回复
热议问题