Scrapy 爬虫学习

scrapy shell "http://quotes.toscrape.com/page/1/" #windows系统必须使用双引号,否则报错ValueError: invalid hostname: 'http
>>> response.css('title') #返回一个名为List的对象SelectorList,表示包含Selector的XML/HTML元素的对象列表,允许用户运行进一步的查询来细分选择或提取数据
[<Selector xpath=u'descendant-or-self::title' data=u'<title>Quotes to Scrape</title>'>]
>>> response.css('title::text').extract() #提取文本,添加::text意味着在元素内部获取文本元素
[u'Quotes to Scrape']
>>> response.css('title').extract() #没有添加::text,将获得完整的元素,包括其标签
[u'<title>Quotes to Scrape</title>']

猜你喜欢

转载自blog.csdn.net/u011378313/article/details/79140638