Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Chore] Improve structure of GoogleSearcher #11

Open
olivierobert opened this issue Nov 28, 2023 · 4 comments · Fixed by #15
Open

[Chore] Improve structure of GoogleSearcher #11

olivierobert opened this issue Nov 28, 2023 · 4 comments · Fixed by #15
Assignees

Comments

@olivierobert
Copy link

Issue

The code business logic for the scraper is contained in one method of 30 lines with many inline variables (e.g., DOM selectors for the ads, Google URL).

Expected

Use OOP best practices to structure GoogleSearcher:

  • Extract parts of the business logic into small methods with a single responsibility
  • Define hard-coded values into constants
@tajul-saajan
Copy link
Owner

Extract parts of the business logic into small methods with a single responsibility

inside page.evaluate() function runs in the browser context, not in the node.js context. So it does not work when I separate the calculation of different properties in private functions. is it acceptable to define functions for calculating intended variables?

@olivierobert
Copy link
Author

That is indeed the challenge to solve 💦 The solution is to work off a string of the scraped page instead of a process. For that, the most standard solution is to 1) fetch the HTML content of the Google search page (this can be done with fetch, axios or any HTTP request library) and 2) use https://www.npmjs.com/package/cheerio to parse the HTML page for the required content.

@tajul-saajan
Copy link
Owner

At first. I considered both axios, cheerio combination and puppeteer for scraping. Eventually, decided to use puppeteer for its convenience to use as it imitates a regular browser and supports javascript dom.

@tajul-saajan
Copy link
Owner

the last commit on the #15 pr implements searcher based on axios and cheerio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants