Making API request with crawlee?
I need to make an api POST request to retrieve information in the body . I tried using the Basic crawler, since it uses Got-scrapping under the hood. I've had no success and I optedfor installing an axios package instead.
The code
11 Replies
foreign-sapphire•3y ago
And what is the exact problem you have?
like-goldOP•3y ago
I just wanted to understand why it didn't work with BasicCrawler, is there a mistake in my code?
foreign-sapphire•3y ago
I cannot tell because I would have to analyze that you are passing everything correctly. Look at the
got
library for correct paramscomplex-teal•3y ago
HTTP crawler | Crawlee
This example demonstrates how to use HttpCrawler to crawl a list of URLs from an external file, load each URL using a plain HTTP request, and save HTML.
like-goldOP•3y ago
How can I use Http crawler for a post request with custom headers and body ?
@Joaquim just advanced to level 2! Thanks for your contributions! 🎉
complex-teal•3y ago
Here's an example:
complex-teal•3y ago
I'd recommend checking out the
RequestOptions
interface to understand all the options available:
https://crawlee.dev/api/core/interface/RequestOptionsRequestOptions | API | Crawlee
Specifies required and optional fields for constructing a {@apilink Request}.
like-goldOP•3y ago
Thanks really helpful, I guess I won't need install axios in future projects after I master this
foreign-sapphire•3y ago
You can also do any extra HTTP with
context.sendRequest
from the handlerlike-goldOP•3y ago
Isn't it more convenient or equal to use addRequest ?