python - Scrapy not getting date as item argument -


i have code, want add item argument current date, i've found different solutions on web keep getting typeerror: 'str' object not callable or typeerror: 'itemmeta' object not support item assignment

my code this:

datascrape = time.strftime("%d/%m/%y") #also tried str(datetime.datetime.today()) item['dataoggi'] = datascrape() #i tried datascrape without () 

how can item argument date of scrape?

updated code:

from bot.items import botitem import time  class netbotspider(scrapy.spider): name = "netbot" allowed_domains = ["example.com"] start_urls = (     'http://example.com )  def parse(self, response):      stati = response.xpath('/html/body//div/table/tbody//tr//td//img//@title').extract()     numeri = response.xpath('/html/body//div/table/tbody//tr[2]//td/text()').extract()     in range(1, len(stati)):         item = botitem()         datascrape = time.strftime("%d/%m/%y")         botitem['dataoggi'] = datascrape         botitem['state'] = stati[i]         botitem['number'] = numeri[i]      print botitem 

typeerror: 'str' object not callable

you should not calling datascrape - string:

item['dataoggi'] = datascrape 

typeerror: 'itemmeta' object not support item assignment

this, means trying add field item class, not instance. replace:

item = botitem() datascrape = time.strftime("%d/%m/%y") botitem['dataoggi'] = datascrape botitem['state'] = stati[i] botitem['number'] = numeri[i] 

with:

item = botitem() datascrape = time.strftime("%d/%m/%y") item['dataoggi'] = datascrape item['state'] = stati[i] item['number'] = numeri[i] 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -