scrapy爬虫提取网页链接的两种方法以及构造HtmlResponse对象的方式
Response对象的几点说明: Response对象用来描述一个HTTP响应,Response只是一个基类,根据相应的不同有如下子类: TextResponse,HtmlResponse,XmlResponse 仅以HtmlResponse为例,HtmlResponse在基类Response的基础上,还多了很多新的方法。 一.使用Selector 因为链接也是页面中的数据,所以可以使用与提取数据相同的方法进行提取。在分析网页时可以通过jupyter notebook构造selector对象进行分析(selector对象有xpath和css方法) import requests from scrapy.selector import Selector res=requests.get("http://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html") selector=Selector(response=res) 二 . 使用 scrapy框架中的linkextractors模块 用法见相关资料 1. le.extractor_links(response)中的response指的是HtmlResponse