Answer the question
In order to leave comments, you need to log in
Scrapy. How to optimize the code?
I parse the page using Scrapy https://www.reformagkh.ru/myhouse/profile/view/7913930/
I
wrote the following code:
def parse_item(self, response):
hxs = HtmlXPathSelector(response)
l = ReformaLoader(ReformaItem(), hxs)
l.add_xpath('house', '/html/body/div[1]/div[2]/h1/span[2]/span[1]/text()')
l.add_xpath('organization', '/html/body/div[1]/div[2]/section/div[1]/table[1]/tbody/tr/td[2]/a/text()')
l.add_xpath('year',
'/html/body/div[1]/div[2]/div[7]/div/div/div[1]/div/div/table/tbody/tr[4]/td[2]/span/text()')
return l.load_item()
titles = hxs.xpath("//table[@class='orders overhaul-services-table']//tr")
for titles in titles:
l.add_xpath(????)
Answer the question
In order to leave comments, you need to log in
I have never worked with Scrapy, but I think you need to look towards relative xpath queries in the style:
titles = hxs.xpath("//table[@class='orders overhaul-services-table']//tr")
for title in titles:
item['year'] = title.xpath('./td[2]/span/text()').extract()
item['organization'] = title.xpath('./td[2]/a/text()').extract()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question