Extracting html from website using a code node instead of an extract node

I would like to extract data from html using a code node instead of the extract node, I tried doing it using DOM, but that doesn’t work with n8n if I’m not mistaken. Is there any other way to do it?

Hey @duler_rok,

Welcome to the community :tada:

If you wanted to use the code node you would first need to load the page with it which will probably need an external library installed.

What are you actually trying to do? It may help us think of a way to get it working.

I am trying to get some general book data like title, url and description from https://www.bookdepository.com/ and then send the data to an email. I got it working using the extract node, but now I would like to do it with the code node.

This is how I did it with the extract node

Hey @duler_rok,

Perfect, So in the Code node if you want to reproduce all of that up to the Item Lists node you would need to reproduce the behaviour of the HTTP Request node and HTML Extract nodes so the first thing to do would be to find an HTTP request package you are happy with using then importing it into the code node and using it like normal from there. Then it would just be a case of working through the HTML string that is returned.

So you could use something like…

const request = require('request-promise-native');

const options = {
  uri: 'https://www.bookdepository.com/category/1708/Technology-Engineering',
  method: 'GET',
  json: false
}

let result = await request(options);
return [{data: result}];

Which will give you this back…

Then it will be down to having fun parsing that.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.