我是Scrapy新手,刚开始研究XPath。
我正试图从一个div中的html列表项中提取标题和链接。下面的代码是我想如何进行的(选择ul div,按I d,然后在列表项中循环):def parse(self, response):
for t in response.xpath('//*[@id="categories"]/ul'):
for x in t.xpath('//li'):
item = TgmItem()
item['title'] = x.xpath('a/text()').extract()
item['link'] = x.xpath('a/@href').extract()
yield item
但我得到的结果和这次尝试一样:def parse(self, response):
for x in response.xpath('//li'):
item = TgmItem()
item['title'] = x.xpath('a/text()').extract()
item['link'] = x.xpath('a/@href').extract()
yield item
其中导出的csv文件包含从源代码到下的li数据。。。
我不是专家,我已经做了很多尝试,如果有人能对此有所了解,我将不胜感激。