Skip to content

Fix rating extraction - update selectors for 2026 Google Maps layout#1

Open
Ayush0126 wants to merge 1 commit into
Petey1337:mainfrom
Ayush0126:fix-rating-extraction
Open

Fix rating extraction - update selectors for 2026 Google Maps layout#1
Ayush0126 wants to merge 1 commit into
Petey1337:mainfrom
Ayush0126:fix-rating-extraction

Conversation

@Ayush0126

Copy link
Copy Markdown

Problem

The current rating extraction method using .fzvQIb selector no longer works with Google Maps' updated layout (as of January 2026). Reviews are scraped successfully but ratings show as 0.

Solution

Updated the rating extraction logic with multiple fallback methods:

  1. Primary method: Extract from aria-label attribute on star rating images (most reliable)
  2. Fallback method 1: Count visible star span elements
  3. Fallback method 2: Keep original text-based method for backward compatibility

Testing

  • ✅ Tested with multiple business pages
  • ✅ All ratings extracted correctly (1-5 stars)
  • ✅ No breaking changes to existing functionality
  • ✅ Backward compatible with older layouts

Changes Made

  • Modified rating extraction in extractReviews() function (scraper.js, lines ~180-190)
  • Added multi-method rating detection with fallbacks
  • Improved robustness for different Google Maps layouts

Code Changes

// Old code (not working):
const ratingTextEl = review.querySelector('.fzvQIb');
if (ratingTextEl) {
  const ratingText = ratingTextEl.textContent.trim();
  const ratingMatch = ratingText.match(/(\d+)/);
  rating = ratingMatch ? parseInt(ratingMatch[1]) : 0;
}

// New code (working):
const ratingImg = review.querySelector('[role="img"][aria-label]');
if (ratingImg) {
  const ariaLabel = ratingImg.getAttribute('aria-label');
  const match = ariaLabel.match(/(\d+)/);
  if (match) rating = parseInt(match[1]);
}

Fixes issue where ratings were showing as 0 for all reviews.

@Ayush0126

Copy link
Copy Markdown
Author

Before

image

After

image

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 this pull request may close these issues.

1 participant