# -*- coding: utf-8 -*-

import urllib
from lxml import etree

__author__ = 'florije'


def get_html(url):
    page = urllib.urlopen(url)
    html = page.read()
    return html


def get_key(html):
    page = etree.HTML(html.lower().decode('gb2312'))
    trs = page.xpath(u"//td[@valign='top']/font[@size='2']//table[contains(@width,'100%')]/tr")
    i = 1
    size = len(trs)
    while (i < size):
        ip = trs[i].xpath("./td[2]/text()")[0]
        port = trs[i].xpath("./td[3]/text()")[0]
        i = i + 1
        print ip + "    " + port


if __name__ == '__main__':
    i = 1
    total_page = 12
    while i < total_page:
        addr = "http://www.proxy.com.ru/list_" + str(i) + ".html"
        html = get_html(addr)
        key = get_key(html)
        i += 1
