coding UTF-8 import urllib import csv import logging from grab spider

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# -*- coding: UTF-8 -*-
import urllib
import csv
import logging
from grab.spider import Spider, Task
from grab import Grab
from grab.selector import Selector
from lxml.html import fromstring
class DBSpider(Spider):
initial_urls = ['http://www.minsktrans.by/mg/suburb.php']
results = []
def task_initial(self, grab, task):
for g in grab.doc('//select[@id="minsk0"]/option'):
print g.select('@value').text().encode('utf8')
print g.text().encode('utf8')
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
bot = DBSpider()
bot.run()
print re.findall('(\d+)', g.select('/a/@onclick').text())
print g.text()