From what I gathered, it is indeed possible to call a JS function from python (using js2py for example).
However, is it possible to do that when the JS code depends on additional libraries?
JS code:
const puppeteer = require('puppeteer');
async function shorturl(link) {
const browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();
await page.goto("https://www.shorturl.at", { waitUntil: 'networkidle0' });
await page.waitForSelector('input[name=u]');
await page.$eval('input[name=u]', (el, value) => el.value = value, link);
await page.click('input[type="submit"]');
// await page.waitForNavigation();
await page.waitForSelector('#shortenurl');
const result = await page.evaluate(() => {
const anchor = document.querySelector('#shortenurl').value;
return anchor;
});
console.log(result);
await browser.close();
return result;
};
My main goal is to allow python to execute a JS script that is meant to extract a short URL link from a website.
It took me a while to figure out how to perform that task with JS.
If I have to, I'll try to find a way to execute the same thing in python.