How to Extract Resolved Link URLs from an HTML file in Node.js

Cloudmersive
2 min readDec 8, 2023

--

Whether we’re looking to feed our web crawlers more efficiently or simply verify that URL links work correctly, programmatically removing resolved URL links from our HTML files saves us precious time.

Using the ready-to-run code provided below, we can take advantage of a free API that automatically removes resolve link URLs from our HTML files and returns those URLs — along with their anchor text — in a series of simple response objects.

To make our API request for free, we’ll just need a free-tier API key — this will allow us to make up to 800 API calls per month with no additional commitment.

To begin structuring our API call, let’s first install the SDK. We can either run this command:

npm install cloudmersive-convert-api-client --save

Or we can add this snippet to our package.json:

  "dependencies": {
"cloudmersive-convert-api-client": "^2.6.3"
}

Lastly, we can include the below code in our file and set our request parameters:

var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');
var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;

// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';



var apiInstance = new CloudmersiveConvertApiClient.EditHtmlApi();

var opts = {
'inputFile': Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer), // File | Optional: Input file to perform the operation on.
'inputFileUrl': "inputFileUrl_example", // String | Optional: URL of a file to operate on as input.
'baseUrl': "baseUrl_example" // String | Optional: Base URL of the page, such as https://mydomain.com
};

var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.editHtmlHtmlGetLinks(opts, callback);

Just like that, we’re all done — no more code required!

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet