Postcode districts

10 views
Skip to first unread message

Anna Powell-Smith

unread,
May 9, 2012, 5:41:32 AM5/9/12
to scrap...@googlegroups.com
Hello

I want to scrape one of those annoying pages where the only way to get
results is by entering a postcode:
http://www.marksandspencer.com/mn/storeLocator (I want to get a full
store list)

It will at least accept a postcode district rather than a full
postcode, so I can use that as a start. I don't suppose ScraperWiki
has a list of postcode districts in-built? Or any suggestions for a
smarter way to scrape this page? Grateful for any ideas.

thanks
Anna

Páll Hilmarsson

unread,
May 9, 2012, 6:16:40 AM5/9/12
to scrap...@googlegroups.com
Hi Anna.

Here is a scraper with the postcode districts:
https://scraperwiki.com/scrapers/uk_postcode_districts/

You can attach it to your scraper and use it to submit in the search form.

All the best,

pallih
--
pal...@kaninka.net
http://gogn.in
http://twitter.com/pallih
http://is.linkedin.com/in/pallih

My email load: http://courteous.ly/KbEbzo

'Dragon' Dave McKee

unread,
May 9, 2012, 4:04:47 PM5/9/12
to scrap...@googlegroups.com

I have a cunning project planned to build a small list of postcodes such that every postcode is within X miles of one postcode on the list. Haven't quite worked out the best way of doing the maths yet, though, so I wouldn't hold your breath on that.

Anna Powell-Smith

unread,
May 9, 2012, 4:48:37 PM5/9/12
to scrap...@googlegroups.com
That would be useful!

Thanks for the scraper link, Páll. For future reference, here is the
full code snippet I used:

POSTCODE_URL = 'https://api.scraperwiki.com/api/1.0/datastore/sqlite?format=jsonlist&name=uk_postcode_districts&query=select%20postcode_district%20from%20%60uk_postcode_districts%60'
jsonurl = urllib2.urlopen(POSTCODE_URL).read()
jsondata = json.loads(jsonurl)['data']
postcode_districts = [p[0] for p in jsondata]

Julian Todd

unread,
May 15, 2012, 11:20:58 AM5/15/12
to scrap...@googlegroups.com
Do this with a greedy algorithm.

Use the OSGB grid coordinates for each postcode for best results.

1. Pick postcode in middle of the country and add it to the set P.

2. Pick another postcode not in P whose minimum distance to any
postcode in P is maximal, and add it to P.

3. Repeat step 2 as long as you like.

4. The set of postcodes becomes progressively more dense as you go
down the list. You may want to record the minimal distance from step
2 in the same table to make it possible to estimate this.

JT


On 9 May 2012 21:04, 'Dragon' Dave McKee <dave....@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages