Scrapy: Extract links and text

后端 未结 2 1952
生来不讨喜
生来不讨喜 2020-12-29 05:42

I am new to scrapy and I am trying to scrape the Ikea website webpage. The basic page with the list of locations as given here.

My items.py file is

相关标签:
2条回答
  • 2020-12-29 05:52

    There is a simple mistake inside the xpath expressions for the item fields. The loop is already going over the a tags, you don't need to specify a in the inner xpath expressions. In other words, currently you are searching for a tags inside the a tags inside the td inside tr. Which obviously results into nothing.

    Replace a/text() with text() and a/@href with @href.

    (tested - works for me)

    0 讨论(0)
  • 2020-12-29 05:59

    use this....

        item['name'] = sel.xpath('//a/text()').extract()
        item['link'] = sel.xpath('//a/@href').extract()
    
    0 讨论(0)
提交回复
热议问题