bernardotonin / real-state-scraper

0 stars 0 forks source link

Erro! #2

Open DeLuca92 opened 4 hours ago

DeLuca92 commented 4 hours ago

Estou tentando usar o projeto estou com alguns erros :/

Deu quase tudo certo MAS

no npm start da o seguinte erro

pm start 
npm ERR! Missing script: "start"
npm ERR! 
npm ERR! Did you mean one of these?
npm ERR!     npm star # Mark your favorite packages
npm ERR!     npm stars # View packages marked as favorites
npm ERR! 
npm ERR! To see a list of scripts, run:
npm ERR!   npm run

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/daniel/.npm/_logs/2024-11-01T21_27_23_202Z-debug-0.log

Dai coloquei npm run dev

> scrapper@1.0.0 dev
> tsx watch src/

node:internal/errors:496
    ErrorCaptureStackTrace(err);
    ^

TypeError [ERR_INVALID_URL]: Invalid URL
    at __node_internal_captureLargerStackTrace (node:internal/errors:496:5)
    at new NodeError (node:internal/errors:405:5)
    at new URL (node:internal/url:676:13)
    at HttpsProxyAgent (/home/daniel/Desktop/zapimoveis/real-state-scraper/node_modules/https-proxy-agent/src/index.ts:54:44)
    at <anonymous> (/home/daniel/Desktop/zapimoveis/real-state-scraper/src/lib/constants.ts:11:27)
    at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:336:24)
    at async loadESM (node:internal/process/esm_loader:34:7)
    at async handleMainPromise (node:internal/modules/run_main:106:12) {
  input: '',
  code: 'ERR_INVALID_URL'
}

Node.js v18.19.1

Saberia me ajudar?

bernardotonin commented 2 hours ago

Boa noite, DeLuca92!

O readme está errado, o comando para rodar é de fato o npm run dev, peço desculpas por isso.

Quanto ao segundo erro, ele refere-se ao endereço proxy. Essa aplicação foi desenvolvida em um ambiente corporativo, onde se fazia necessário a autenticação via proxy. Para rodar a aplicação sem proxy, faça as seguintes alterações:

src/scraper/zap.ts

  from: number,
  size: number
): Promise<PrismaProperty[]> => {
  const response = await fetch(getZapUrl(from, size), {
    agent: ProxyAgent, // <-- remover essa linha.
    headers: ZapHeaders,
  });
  const json = await response.json() as ZapJSON;
  return parseJson(json.search.result.listings);
};

export const getZapCount = async (): Promise<number> => {
  const response = await fetch(getZapUrl(0, 3), {
    agent: ProxyAgent, // <-- remover essa linha
    headers: ZapHeaders,
  });
  const json = await response.json() as ZapJSON;
  return Math.floor(json.search.totalCount / 108);
};

src/scraper/viva.ts

  const response = await fetch(getVivaUrl(0, 0), {
    agent: ProxyAgent, // <-- remover essa linha
    headers: VivaHeaders,
  });
  const json = await response.json() as ZapJSON;
  return Math.floor(json.search.totalCount / 108);
};

export const fetchFromViva = async (
  from: number,
  size: number
): Promise<PrismaProperty[]> => {
  const response = await fetch(getVivaUrl(from, size), {
    agent: ProxyAgent,  // <-- remover essa linha
    headers: VivaHeaders,
  });
  const json = await response.json() as ZapJSON;
  return parseJson(json.search.result.listings);
};

Peço desculpas por não elaborar o uso do proxy no readme, irei atualizar assim que possivel.

Caso tenha qualquer outro erro, ficarei feliz em ajudar-lo.

Atenciosamente, Bernardo Tonin.