1.以utf8方式打开文件:
import io with io.open(filename,"w",encoding="utf8") as f
2.以追加方式写入文件:
import io with io.open(filename,"a",encoding="utf8") as f
3.关于xpath()[0]
后面加0代表着可能抽取到多个元素,在这么多元素中取第一个满足条件的;比如下图:
div底下有两个a;若想取第一个,可这么写xpath('//div[@class = "list-footer"]/a/text()')[0].extract()
若想取第二个a,可这么写:xpath('//div[@class = "list-footer"]/a/text()')[1].extract()
4.使用scrapy抓取数据的时候,用时候会被网站的robots 协议禁止抓取;具体表现为:[scrapy] DEBUG: Forbidden by robots.txt;因为scrapy默认是遵循robots协议的;如果还是像抓取,可在settings.py文件中设置:ROBOTSTXT_OBEY=False