Skip to content

Instantly share code, notes, and snippets.

@alamkanak
Last active December 21, 2020 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alamkanak/808affaeae225ef8615f86df217f2a10 to your computer and use it in GitHub Desktop.
Save alamkanak/808affaeae225ef8615f86df217f2a10 to your computer and use it in GitHub Desktop.
Foodpanda sorting by rating

Sort foodpanda restaurants

Using this script on any browser, you can sort the restaurants listed in the foodpanda website by rating or review count.

  1. Visit foodpanda.com and select your location.
  2. Keep scrolling down to the bottom of the page until all resaurants are loaded on the page.
  3. In Chrome, right click anywhere on the page and select Inspect from the menu.
  4. In the Inspect window click the Console tab.
  5. In the console, paste in the following script and hit enter.
var name, ratingElement, rating, categories, cats, deliveryTime, budget, count;
var pattern = /(.*?)\/5 \((.*?)\)/i;
var thousandPattern = /(.*?)k\+/i;
var restaurants = []
var rs = document.getElementsByClassName("vendor-tile");
for (var i = 0; i < rs.length; i++) {

	// Name.
	name = rs.item(i).getElementsByClassName('name').item(0).textContent;

	// Categories.
	cats = rs.item(i).getElementsByClassName('vendor-characteristic').item(0);
	cats = cats.getElementsByTagName('span');
	categories = [];
	for (var j = 0; j < cats.length; j++) {
		categories.push(cats.item(j).textContent);
	}

	// Rating and review count.
	ratingElement = rs.item(i).getElementsByClassName('ratings-component').item(0);
	rating = 0
	count = 0
	if (ratingElement != null) {
		rating = parseFloat(ratingElement.textContent.match(pattern)[1]);
		count = ratingElement.textContent.match(pattern)[2];
		if (!isNaN(count)) {
			count = parseInt(count);
		}
		else {
			count = parseInt(count.match(thousandPattern)[1]) * 1000;
		}
	}

	// Delivery time.
	deliveryTime = rs.item(i).getElementsByClassName('badge-info').item(0).textContent;
	
	// Budget.
	budget = rs.item(i).getElementsByClassName('budget-symbol--filled');
	budget = budget.length + "/3";

	restaurants.push({
		name: name, 
		rating: rating, 
		count: count, 
		categories: categories.toString(), 
		delivery_time: deliveryTime, 
		budget: budget
	});
}

// Remove duplicates.
restaurants = restaurants.filter((v,i,a) => a.findIndex(t => (t.name === v.name && t.count === v.count))===i)
console.table(restaurants);
  1. You will be presented with a table of restaurants. Now click on rating or count column name to sort by ascending or descending order.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment