Update zestimate to use puppeteer instead of selenium
Create and publish Docker image on GHCR / publish-docker-image (push) Has been cancelled
Create and publish Docker image on GHCR / publish-docker-image (push) Has been cancelled
This commit is contained in:
+42
-22
@@ -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 api = require('@actual-app/api');
|
||||||
const { closeBudget, ensurePayee, getAccountBalance, getAccountNote, getTagValue, openBudget, showPercent, sleep } = require('./utils');
|
const { closeBudget, ensurePayee, getAccountBalance, getAccountNote, getTagValue, openBudget, showPercent, sleep } = require('./utils');
|
||||||
require("dotenv").config();
|
require("dotenv").config();
|
||||||
|
|
||||||
|
puppeteer.use(StealthPlugin());
|
||||||
|
|
||||||
async function getZestimate(URL) {
|
async function getZestimate(URL) {
|
||||||
let driver = await new Builder()
|
const browser = await puppeteer.launch({
|
||||||
.forBrowser(Browser.CHROME)
|
headless: 'new',
|
||||||
.build();
|
args: ['--no-sandbox', '--disable-setuid-sandbox']
|
||||||
|
});
|
||||||
|
|
||||||
|
const page = await browser.newPage();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await driver.get(URL);
|
await page.goto(URL, { waitUntil: 'domcontentloaded', timeout: 20000 });
|
||||||
const html = await driver.wait(until.elementLocated(By.css('body')), 5000).getAttribute('innerHTML');
|
const html = await page.content();
|
||||||
|
try {
|
||||||
try {
|
console.log('Got html data!');
|
||||||
let match = html.match(/\\?"zestimate\\?":(\d+)/);
|
let match = html.match(/"price":"(\d+)"/);
|
||||||
if (match) {
|
if (match) {
|
||||||
return parseInt(match[1]) * 100;
|
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+)/);
|
} catch (er) {
|
||||||
if (match) {
|
console.log('Error while fetching zestimate:');
|
||||||
return parseInt(match[1]) * 100;
|
console.log(er);
|
||||||
}
|
console.lo(html);
|
||||||
} catch (error) {
|
|
||||||
console.log('Error parsing Zillow page:');
|
|
||||||
console.log(error);
|
|
||||||
console.log(html);
|
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
await driver.quit();
|
await browser.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user