Skip to content

Mercato is a console application that will scrape a Sainsbury's test page

Notifications You must be signed in to change notification settings

edoardo849/mercato

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mercato: a Sainsbury's Scraper in Go

DISCLAIMER ⚠️

Please be aware that Sainsbury's code reviewers are aware of this project and could compare it against your submission. Take inspiration if you want, but don't copy it: be creative instead! :-)

Logic

Mercato is a console application intended to scrape a Saynsbury's test page and grab every product's url children page for additional information.

This task could be completed with PHP, Java or Go. However, Go seems the better and logic candidate because of the possibility to run every scrape request as a concurrent goroutine, thus augmenting the response time.

Notes

GoRoutines order

When we are scraping the store's page, the order of each product in the final JSON object will not be the same as the order of appearance on the page. This is because of the GoRoutine's concurrency: the actual order will probably be determined by the responsiveness of the queried page.

If the order of the products in the final JSON object should be the same as the one of the grocery store page, it will be necessary to add an order param on the struct sainsburys.Product and then implement an order func afterwards.

Because of time restraints, this has been left out.

Dependencies

Installation

# Clone the repo
git clone [email protected]:edoardo849/mercato.git

# Enter the directory
cd mercato

# Install the go dependencies
go get

# Run all the tests
go test ./...

# Run the scraper
go run main.go

Example output from the console

{
	"results":[
	{
		"title":"Sainsbury's Apricot Ripe & Ready x5",
			"size":"38.27kb",
			"unit_price":3.50,
			"description":"Buy Sainsbury's Apricot Ripe & Ready x5 online from Sainsbury's, the same great quality, freshness and choice you'd find in store. Choose from 1 hour delivery slots and collect Nectar points."
	},
	{
		"title":"Sainsbury's Golden Kiwi x4",
		"size":"38.56kb",
		"unit_price":1.80,
		"description":"Buy Sainsbury's Golden Kiwi x4 online from Sainsbury's, the same great quality, freshness and choice you'd find in store. Choose from 1 hour delivery slots and collect Nectar points."
	}
	],
	"total":15.10
}

About

Mercato is a console application that will scrape a Sainsbury's test page

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages