Привет, у меня проблема с моим скриптом-пауком, я хотел, чтобы мой скрипт был максимально читабельным, и я хотел сохранить как можно больше кода.Можно ли использовать один и тот же синтаксический анализ для разных URL-адресов?
Я хотел собрать только 10 элементов на странице и сохранить его на разных элементах в items.py
Вот мой код
def start_requests(self): #I have 3 URL's Here
yield scrapy.Request('https://teslamotorsclub.com/tmc/post-ratings/6/posts', self.parse) #Url 1
yield scrapy.Request('https://teslamotorsclub.com/tmc/post-ratings/7/posts', self.parse) #Url 2
yield scrapy.Request('https://teslamotorsclub.com/tmc/post-ratings/1/posts', self.parse) #Url 3
def parse(self, response): #My logic is something like this
if Url == Url1:
item = TmcnfSpiderItem()
elif Url == Url2:
item = TmcnfSpiderItem2()
elif Url == Url3:
item = TmcnfSpiderItem3()
if count <= 9:
count += 1
info = response.css("[id^='fc-post-" + postno_only +"']")
author = info.xpath("@data-author").extract_first()
item['author'] = author
yield item
else:
#Move to next URL and perform same parse
Есть идеи?