admin管理员组

文章数量:1279015

I am working with JS+Puppeteer and I'm trying to make a script that can add items to cart. The website will often crash due to high traffic, so instead of relying on clicking, I want the script to send the item info directly to the backend. Once it does that, it will continue to do things. The add-to-cart link is different from the website's link.

For example, the website is abc.shop, and the backend API address is abc.shop/api/... I want to send a JSON continuing the item data to the api address.

Is it possible to send a POST request using puppeteer to a different address, and if so, how?

I am working with JS+Puppeteer and I'm trying to make a script that can add items to cart. The website will often crash due to high traffic, so instead of relying on clicking, I want the script to send the item info directly to the backend. Once it does that, it will continue to do things. The add-to-cart link is different from the website's link.

For example, the website is abc.shop, and the backend API address is abc.shop/api/... I want to send a JSON continuing the item data to the api address.

Is it possible to send a POST request using puppeteer to a different address, and if so, how?

Share Improve this question asked Oct 2, 2020 at 23:46 Arthur XuArthur Xu 311 silver badge2 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 11

You can use page.evaluate to send a post request using fetch api.

await page.evaluate(() => {
  return fetch('url', {method: 'POST', body: 'test' }).then(res => res.json());
});

https://pptr.dev/#?product=Puppeteer&version=v3.3.0&show=api-pageevaluatepagefunction-args

本文标签: javascriptSend POST request in puppeteerStack Overflow