Not exactly what you asked, but probably close enough could be achieved by:
- installing chrome-headless
- setting up nodejs + couple of modules
- getting the loaded and parsed with client side events outerHTML
- reading from perl code the outerHTML
as follows:
# just a perl oneliner, parsing the scrapped html and passing it to Mojo::DOM
perl -MMojo::DOM -e '$s=`node scrap-html.js`; for my $e (Mojo::DOM->new($s)->find("html body a.scroll")->each){ print $e->text}';
where the code for the scrap-html.js
// file: scrap-html.js src: https://gist.github.com/magician11/a979906401591440bd6140bd14260578
const CDP = require('chrome-remote-interface');
const chromeLauncher = require('chrome-launcher');
(async function() {
const launchChrome = () =>
chromeLauncher.launch({ chromeFlags: ['--disable-gpu', '--headless','--blink-settings=imagesEnabled=false'] });
const chrome = await launchChrome();
const protocol = await CDP({ port: chrome.port });
const timeout = ms => new Promise(resolve => setTimeout(resolve, ms));
// See API docs: https://chromedevtools.github.io/devtools-protocol/
const { Page, Runtime, DOM } = protocol;
await Promise.all([Page.enable(), Runtime.enable(), DOM.enable()]);
uri = 'https://qto.fi/qto/view/readme_doc'
Page.navigate({ url: uri });
// wait until the page says it's loaded...
Page.loadEventFired(async () => {
try {
await timeout(4000); // give the JS some time to load
// get the page source
const rootNode = await DOM.getDocument({ depth: -1 });
const pageSource = await DOM.getOuterHTML({
nodeId: rootNode.root.nodeId
});
protocol.close();
chrome.kill();
console.log ( pageSource.outerHTML)
} catch (err) {
console.log(err);
}
});
})();
//eof file: scrap-html.js
example for the whole setup on ubuntu:
# start install chromium-headless
sudo apt-get update
sudo apt-get install -y software-properties-common
sudo apt-get install -y chromium-browser
sudo apt-get update
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb
apt --fix-broken install
# stop install chromium-headless
# start installing the nodejs + node modules
sudo apt install nodejs
sudo npm install -g chrome-remote-interface
sudo npm install -g chrome-launcher
export NODE_PATH=/usr/local/lib/node_modules
# stop installing the nodejs + modules