if response.xpath("//li[@class='next']/a/@href") is not None : # index list out of range
这里response.xpath("//li[@class='next']/a/@href")如果找不到的话,会返回一个空列表,但不是None
可以用 if len(response.xpath("//li[@class='next']/a/@href")): 来判断
======2017-12-16更新======
# docs.scrapy.org # If you want to extract only first matched element, you can call the selector .extract_first() # It returns None if no element was found. # 上面也可以改成: if response.xpath("//li[@class='next']/a/@href").extract_first() is not None:
response.xpath("//li[@class='next']/a/@href") is not None
最新推荐文章于 2025-02-14 17:17:16 发布