HTQL - the Hyper-Text Query Language


What is HTQL

Hyper-Text Query Language (HTQL) is a language for the querying and transformation of HTML, XML and plain text documents. HTQL is developed in C++ with fast and efficient data extraction algorithms. HTQL provides COM and Python interfaces for use in JavaScript, Visual Basic, .NET, ASP, and Python applications. HTQL can be used to:
  1. Extract data from HTML Web pages
  2. Retrieve HTML page through HTTP protocol
  3. Modify HTML pages from applications
In addition, the HTQL Python package includes some text search libraries that are implemented in C++ and optimized for efficient search of large-volume data, including regular expression search, dictionary search, similar string search, and text clustering. Please refer the Python Interface manual for their usage.



Python Installation
  1. Windows binaries: Download the and extract "htql.pyd" to the Python's DLLs directory, such as in 'C:\Python27\DLLs\' or 'C:\Python32\DLLs\'.
  2. Python 2.6
    Python 2.7
    Python 3.2
    Python 3.3

  3. Linux binaries: Copy to your library path.
  4. Pthon 2.4, GNU Linux x86.64 (
    Pthon 2.6, GNU Linux x86.64 (
    Pthon 2.7, GNU Linux x86.64 (
    Pthon 3.3, GNU Linux x86.64 (
    Pthon 3.6, GNU Linux x86.64 (
    Pthon 2.6, Debian Linux i686.64 (
    Pthon 2.6, RedHat Linux x86.64 (

  5. From source: Install from github
  6. Go: github

COM Installation

  1. Download the HtqlCom.dll into a local directory, such as 'C:\htql\'.
  2. Register the "HtqlCom.dll" by running: (for Vista and Win 7, you need to run cmd.exe as administrator)
    C:\htql\> regsvr32 HtqlCom.dll


Python Example

A simple example to extract url and text from links.

import htql; 

page="<a href=a.html>1</a><a href=b.html>2</a><a href=c.html>3</a>";

for url, text in htql.HTQL(page, query): 
    print(url, text);

An example using htql.Browser:

import htql;
c=a.goForm("<form>1", {"q":"test"});
for d in htql.HTQL(c[0], "<a (tx like '%test%')>"): 
    print(d);"<a (tx like '%test%' and not (href like '/search%'))>1");

If you have installed IRobotSoft Web Scraper, you can browse the web visually with:


An example to parse state and zip from US address using HTQL regular expression:

import htql; 
address = '88-21 64th st , Rego Park , New York 11374'
states=['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 
	'Delaware', 'District Of Columbia', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 
	'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 
	'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 
	'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma', 
	'Oregon', 'PALAU', 'Pennsylvania', 'PUERTO RICO', 'Rhode Island', 'South Carolina', 'South Dakota', 
	'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 

a.setNameSet('states', states);

state_zip1=a.reSearchStr(address, "&[s:states][,\s]+\d{5}", case=False)[0]; 
# state_zip1 = 'New York 11374'

state_zip2=a.reSearchList(address.split(), r"&[ws:states]<,>?<\d{5}>", case=False)[0]; 
# state_zip2 = ['New', 'York', '11374']
JavaScript Example

The following example shows the use of HTQL in an HTML page with JavaScript. The JavaScript code in this HTML page retrieves the first <a> tag from and show it in the HTML body.

<!--- test.html -->
<html> <base href="">
<script language=JavaScript>
	var a= new ActiveXObject("HtqlCom.HtqlControl");
Visual Basic Example

The following Visual Basic example does the same thing and shows the result in a message box:

' VB example
Dim a As Object
Set a = CreateObject("HtqlCom.HtqlControl")
i = a.setUrl("")
i = a.setQuery("<a>")
MsgBox (a.getValueByIndex(1))

Applications Using HTQL