Я создаю паука в Scrapy. И я хочу очистить таблицу следующим образом:
- Взять каждые
<tr>
- Использовать
<th>
в качестве ключа и <td>
в качестве содержимого
Код, который я придумал, такой:
def parse(self, response):
item = {}
item['code'] = response.xpath('//meta[@itemprop="sku"]/@content').extract_first()
tables = response.css('.technical-specs')
for table in tables:
specs = tables.xpath('tbody/tr')
for s in specs:
key = s.xpath('th/text()').extract_first().replace(" ", "_").replace("(", "_").replace(")", "_").replace("/", "").lower()
value = s.xpath('td/text()').extract_first()
item[key] = value
return item
Но он не работает. Это возможно для достижения?