Update zestimate to use puppeteer instead of selenium
Create and publish Docker image on GHCR / publish-docker-image (push) Has been cancelled

This commit is contained in:
2026-05-24 09:00:21 -05:00
parent 526cb5fa3a
commit 7899b45e9f
+42 -22
View File
@@ -1,35 +1,55 @@
const { Builder, Browser, By, until } = require('selenium-webdriver')
const puppeteer = require('puppeteer-extra');
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
const api = require('@actual-app/api');
const { closeBudget, ensurePayee, getAccountBalance, getAccountNote, getTagValue, openBudget, showPercent, sleep } = require('./utils');
require("dotenv").config();
puppeteer.use(StealthPlugin());
async function getZestimate(URL) {
let driver = await new Builder()
.forBrowser(Browser.CHROME)
.build();
const browser = await puppeteer.launch({
headless: 'new',
args: ['--no-sandbox', '--disable-setuid-sandbox']
});
const page = await browser.newPage();
try {
await driver.get(URL);
const html = await driver.wait(until.elementLocated(By.css('body')), 5000).getAttribute('innerHTML');
try {
let match = html.match(/\\?"zestimate\\?":(\d+)/);
if (match) {
return parseInt(match[1]) * 100;
await page.goto(URL, { waitUntil: 'domcontentloaded', timeout: 20000 });
const html = await page.content();
try {
console.log('Got html data!');
let match = html.match(/"price":"(\d+)"/);
if (match) {
console.log('matched 1st');
return parseInt(match[1]) * 100;
}
match = html.match(/\\"price\\":(\d+)/);
if (match) {
console.log('matched 2nd');
return parseInt(match[1]) * 100;
}
match = html.match(/\\"price\\":\\"(\d+)\\"/);
if (match) {
console.log('matched 3rd');
return parseInt(match[1]) * 100;
}
console.log('didn\'t match any :(');
console.log('~~!!');
// console.log(html);
console.log('!!~~');
} catch (error) {
console.log('Error parsing Zillow page:');
console.log(error);
console.log(html);
}
match = html.match(/\\?"price\\?":(\d+)/);
if (match) {
return parseInt(match[1]) * 100;
}
} catch (error) {
console.log('Error parsing Zillow page:');
console.log(error);
console.log(html);
}
} catch (er) {
console.log('Error while fetching zestimate:');
console.log(er);
console.lo(html);
} finally {
await driver.quit();
await browser.close();
}
return undefined;
}