from grab import Grab from grab spider import Spider import json cooki

 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
from grab import Grab
from grab.spider import Spider
import json
cookies = {}
with open('cookie.json') as js:
for cookie in json.loads(js.read()):
cookies[cookie["name"]] = cookie["value"]
class MarketSpider(Spider):
initial_urls = ['http://market.yandex.ru']
def task_initial(self, grab, task):
try:
grab.doc.select("//span[@class='user__name']").text()
except IndexError:
print "EBUSHKI VOROBUSHKI, cookies don't work"
else:
print "VSE OK"
bot = MarketSpider()
bot.setup_grab(cookies=cookies)
bot.run()