A python library detect and extract listing data from HTML page.
Switch branches/tags
Nothing to show
Clone or download
tpeng change extraction output format
change it to a dict with record as key and a nested map (mapping from
seed element to target element). this way we know know which data
are extracted from which records, even some data are not existed
for all the records.
Latest commit 573f1ff Sep 10, 2014




MDR is a library detect and extract listing data from HTML page. It implemented base on the Finding and Extracting Data Records from Web Pages but change the similarity to tree alignment proposed by Web Data Extraction Based on Partial Tree Alignment and Automatic Wrapper Adaptation by Tree Edit Distance Matching.


numpy and scipy must be installed to build this package.


Detect listing data

MDR assume the data record close to the elements has most text nodes:

[1]: import requests
[2]: from mdr import MDR
[3]: mdr = MDR()
[4]: r = requests.get('http://www.yelp.co.uk/biz/the-ledbury-london')
[5]: candidates, doc = mdr.list_candidates(r.text.encode('utf8'))

[8]: [doc.getpath(c) for c in candidates[:10]]

Extract data record

MDR can find the repetiton patterns by using tree matching under certain candidate DOM tree, then it builds a mapping from HTML element to other matched elements of the DOM tree.

Used with annotation (optional)

You can annotate the seed elements with any tools (e.g. scrapely) you like, then mdr will be able to find the other matched elements on the page.

e.g. you can find this demo page here. the colored data in first row are annotated manually, the rest are extracted by MDR.


Terry Peng <pengtaoo@gmail.com>