Skip to main content

What is JSDOM?

JSDOM mimics a browser environment, while Htmlparser2 is a fast HTML/XML parser. They are “data processors” and do not perform network requests themselves. You don’t apply proxies to the parser, but you use Oculus Proxies to get the data they parse. Without a proxy-enabled request (via Axios/Fetch), the parser would have no content to process because the target site would likely block the initial data fetch.
If you’re using Oculus to scrape search engines like Google, Bing, or Yandex and facing connection issues, your proxy type may need adjustment. ISP Premium Proxies provide stable and unrestricted access, preventing blocks that standard proxies may encounter. Switching to ISP Premium Proxies can improve performance.

How to Use Oculus Proxies With JSDOM

1

Install package

Install via cmd:
npm install jsdom htmlparser2 axios
2

Example code

Use the following code as an example for JSDOM. Make sure to replace the correct proxy credentials from your dashboard inside response.
const axios = require('axios');
const { JSDOM } = require('jsdom');

async function parseWithProxy() {
// Proxy is used here to fetch the data
const response = await axios.get('http://httpbin.org/ip', {
    proxy: { 
        host: 'proxy.oculus-proxy.com', 
        port: PORT, 
        auth: { username: 'USERNAME', password: 'PASSWORD' } 
    }
});

// The Parser then processes the fetched content
const dom = new JSDOM(response.data);
console.log('Parsed Content:', dom.window.document.body.textContent);
}