Friday, October 4, 2013

Bring HTML Pages Into Relational World Using Web Scraping Teiid Translator

You probably heard many times that we live in the era of Semantic Web. Unfortunately not all HTML pages you see were made using RDF. We have to parse them using web browsers, HTTP clients and a variety of custom tools. Many HTML pages are old, unstructured, were built using outdated standards or poorly designed instruments.
Would be really nice to retrieve all data kept in HTML with minimal effort, and be able to access it in relational way. I had a sleepless night last week, and that's what I came up with.

In short - this is a poor attempt to wrap a great Jsoup java HTML parser in Teiid translator logic. A single example is better than a hundred words. This SQL statement:

SELECT text, attributes
FROM (call scrapedata.scrap('','a[href]')) as S
WHERE upper(text) like '%TEIID%'

Returns this:
Teiid - JBoss Community - Community driven open source … , href="" h="ID=SERP,5095.1"    
Teiid - Downloads - JBoss Community , href="" h="ID=SERP,5108.1"
Teiid Download , href="/search?q=Teiid+Download&FORM=QSRE4" h="ID=SERP,5240.1"
Teiid Designer , href="/search?q=Teiid+Designer&FORM=QSRE5" h="ID=SERP,5241.1"
Teiid Forum , href="/search?q=Teiid+Forum&FORM=QSRE6" h="ID=SERP,5242.1"
Teiid - Tools - JBoss Community , href="" h="ID=SERP,5121.1"
Teiid Installation , Community - JBoss, href="" h="ID=SERP,5134.1"
Teiid - JBoss Issue Tracker , href="" h="ID=SERP,5147.1" 
Teiid 7.0 Installation Guide , href="" h="ID=SERP,5160.1", 
TEIID on tomcat - Community - JBoss, href="" h="ID=SERP,5172.1"

Feel free to get a clone a translator-scrape repository from Github, check the sources, play with - it is a unit test build with Embedded Teiid, should give you an idea of how to use this translator.

1 comment:

  1. Thanks, this is great, Cross posted


Note: Only a member of this blog may post a comment.