Posted 02 Sep 2012 in business and website

sitescraper.net is now webscraping.com!

When I started in this field 3 years ago I was developing the sitescraper tool but now I use the webscraping package for most work, so the domain name change reflects this change. Also the field is commonly known as web scraping so webscraping.com is an awesome domain to have.

The old website and email addresses will be redirected to this new domain.


Posted 25 Aug 2012 in example and learn

CSV stands for comma separated values. It is a spreadsheet format where each column is separated by a comma and each row by a newline. Here is an example CSV file:

    Name,Age,Country
    John,48,United States
    Daniel,67,Germany
    Qi,25,China

You can download this file and view it in Excel, Google Docs, or even directly in a text editor. This same data saved in Excel format uses 4591 bytes and is supported by less applications.

A CSV file can be imported into a database or parsed with a programming language. This flexibility makes CSV the most common output format requested by clients for their scraped data.

Here is an example showing how to parse a CSV file with Python:

import csv
filename = 'example.csv'
reader = csv.reader(open(filename))
for row in reader:
    # display the value at the last column in this row
    print row[-1] 


Posted 09 Jul 2012 in example and python

Recently I needed to convert a large amount of data between UK Easting / Northing coordinates and Latitude / Longitude. There are web services available that support this conversion but they only permit a few hundred requests / hour, which means it would take weeks to process my quantity of data.

Here is the Python script I developed to perform this conversion quickly with the pyproj module:

from pyproj import Proj, transform

v84 = Proj(proj="latlong",towgs84="0,0,0",ellps="WGS84")
v36 = Proj(proj="latlong", k=0.9996012717, ellps="airy",
        towgs84="446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894")
vgrid = Proj(init="world:bng")


def ENtoLL84(easting, northing):
    """Returns (longitude, latitude) tuple
    """
    vlon36, vlat36 = vgrid(easting, northing, inverse=True)
    return transform(v36, v84, vlon36, vlat36)

def LL84toEN(longitude, latitude):
    """Returns (easting, northing) tuple
    """
    vlon36, vlat36 = transform(v84, v36, longitude, latitude)
    return vgrid(vlon36, vlat36)


if __name__ == '__main__':
    # outputs (-1.839032626389436, 57.558101915938444)
    print ENtoLL84(409731, 852012) 

Source code is available on bitbucket.


Posted 20 Jun 2012 in business and website

I have made an app with web2py for listing and selling databases. Hope you like it - and let me know if you have any problems or suggestions.

Around half the databases are free and can be accessed here.


Posted 05 May 2012 in CAPTCHA, OCR, example, and python

Some websites require passing a CAPTCHA to access their content. As I have written before these can be parsed using the deathbycaptcha API, however for large websites with many CAPTCHA’s this becomes prohibitively expensive. For example solving 1 million CAPTCHA’s with this API would cost $1390.

Fortunately many CAPTCHA’s are weak and can be solved by cleaning the image and using simple OCR. Here are some example CAPTCHA images from a recent website I worked with:

Helpfully the distracting marks are lighter so the image can be thresholded to isolate the text:

Now the resulting images can be passed to an OCR program to extract the text. Here are results from 3 popular open source OCR tools:

Captcha 1 Captcha 2 Captcha 3 Result
7rrg5 hirbZ izi3b
Tesseract 7rrq5 hirbZ izi3b 2 / 3
Gocr 7rr95 _i_bz izi3b 1 / 3
Ocrad 7rrgS hi_bL iLi3b 0 / 3

Excellent results. Getting 100% accuracy is not necessary when solving CAPTCHA’s, because real people make mistakes too so websites will just respond with another CAPTCHA to solve.

Tesseract only confused ‘g’ with ‘q’ and Gorc thought that ‘g’ was a ‘9’, which is understandable. Even though Ocrad did not get any correct on this small sample set, it was close every time. And this was without training on the font or fixing the text orientation.

If you are interested the Python code used is available for download here. It depends on the PIL for image processing and each of the OCR tools.


Posted 02 Apr 2012 in business

Business web directories are a great source of data and scraping data from them is a common request from clients. Below are my list of directories that I know of from each country or region. I have noticed that directories for poorer countries often disappear, so let me know if a link no longer works.

Location Business directories
Africa http://www.yellowpagesofafrica.com
Argentina http://www.paginasamarillas.com.ar
Australia http://www.hotfrog.com.au
http://www.yellowpages.com.au
Belgium http://www.pagesdor.be
Belarus http://www.b2b.by
Bolivia http://www.boliviaweb.com/business.htm
Brazil http://www.brazilbiz.com.br
http://www.telelistas.net
http://www.guiamais.com.br
Canada http://www.yellowpages.ca
http://www.ziplocal.ca
Chile http://www.chilnet.cl
http://www.amarillas.cl
China http://www.yellowpage.com.cn
Columbia http://www.quehubo.com/colombia/
Cyprus http://www.cyprusyellowpages.com
Czech Republic http://www.zlatestranky.cz
Denmark http://www.degulesider.dk
http://www.kob.dk
Estonia http://www.ee.ee
Europe http://www.europages.net/a>
Finland http://www.keltaisetsivut.fi
http://www.yritystele.fi
France http://www.pagesjaunes.fr
Germany http://www.businessdeutschland.de
http://www.klicktel.de (same site as http://www.11880.com)
http://www.yellow.de (same site as http://www.gelbeseiten.de)
Greece http://www.xo.gr
Hungary http://www.yellowpages.hu
Iceland http://www.gulalinan.is
India http://www.indiacom.com
Indonesia http://www.yellowpages.co.id
Ireland http://www.yourlocal.ie
http://www.goldenpages.ie
Israel http://www.d.co.il
Italy http://www.paginegialle.it
Japan http://itp.ne.jp
Latin America http://www.paginasamarillas.com
http://directory.centramerica.com
Lebanon http://www.pagesjaunes.com.lb
Lithuania http://www.visalietuva.lt
Malaysia http://www.yellowpages.com.my
Mexico http://seccionamarilla.com.mx
http://www.directory.com.mx
http://www.yellow.com.mx
Middle East http://www.ameinfo.com
Myanmar http://www.myanmaryellowpages.biz
Nepal http://www.nepalhomepage.com/yellowpages/
Netherlands http://www.detelefoongids.nl
New Zealand http://yellow.co.nz
Norway http://www.gulesider.no
Peru http://www.denperu.com.pe/denexe/busqueda.asp
Philippines http://www.eyp.ph
Poland http://www.pkt.pl
Portugal http://www.pai.pt
http://www.guianet.pt
Romania http://www.paginiaurii.ro
Russia http://www.sakh.com
Singapore http://www.yellowpages.com.sg
Spain http://www.paginas-amarillas.es
http://es.qdq.com
Sweden http://gulasidorna.eniro.se
Switzerland http://www.local.ch (same site as http://www.pages-jaunes.ch)
http://www.branchenbuch.ch
Turkey http://www.turkindex.com
Ukraine http://www.ukrainet.com.ua
http://www.mercury.odessa.ua
United Kingdom http://yell.com
http://www.192.com
http://www.scoot.co.uk
United States http://www.yellowpages.com
http://www.superpages.com
http://www.allpages.com
Venezuela http://www.pac.com.ve
Vietnam http://www.vietnamonline.com/yp.html
World http://maps.google.com
http://www.infobel.com