coding utf-8 from grab spider import Spider Task from grab import Grab

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# coding: utf-8
from grab.spider import Spider, Task
from grab import Grab
class ParserAvito:
myGrab = Grab()
myUrl = None
myXPath = None
def getText(self, url, xpath):
self.myUrl = url
self.myXPath = xpath
self.myGrab.go(self.myUrl)
return self.myGrab.doc.select(xpath).text()
site = "http://www.avito.ru/"
site_xpath = ".//*[@id='main']/div[2]/div[1]/div[1]/h2"
par = ParserAvito()
print(par.getText('http://vk.com/',".//*[@id='index']/div[1]/ul/li/span"))