get和getall方法都具有将xpath提取到的数据从selector转换为unicode的作用,只不过get()返回字符串,getall()返回的是一个列表,本人之所以在此点出问题是因为,使用了
chanpinguige = response.xpath("//div[@class=‘properties’]").getall()
然后去遍历,遍历之后xpth的提取方法又用了一次此方法,所以一个为空列表,一个为none,
正确的方法应该为
chanpinguige = response.xpath("//div[@class=‘properties’]"),下面的小标签再逐一用get或者getall获取,就不会报错了,
如response.xpath(".//ul/li/text()").get()就可以了
爬虫中的get()和getall()方法的区别
最新推荐文章于 2024-03-13 11:36:09 发布