python3爬虫开发 Scrapy的使用基本知识

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_36869808/article/details/87908579

笔记

1.安装

这个可以搜索自行安装。

2.scrapy基础使用

1.创建工程
scrapy startproject baidu

2.切换目录
cd baidu

3.创建爬虫
scrapy genspider example baidu.com

4.运行爬虫
scrapy crawl example

3.设置scrapy不遵守robots协议

在文件里有一个settings.py的文件

将robots改为False即可

4.使用python运行scrapy

创建一个main.py

from scrapy import cmdline
cmdline.execute("scrapy crawl example".split())

5.scrapy 使用xpath的方法

在正常的xpath的使用过程中,增加了extract()
eg:

title=response.xpath("//title//text()").extract()

6.scrapy 的文件结构

spiders文件夹:存放爬虫文件的文件夹
items.py:定义需要抓取的数据
pipelines.py:股则数据抓取以后的工作
settings.py:爬虫的各种配置信息

猜你喜欢

转载自blog.csdn.net/qq_36869808/article/details/87908579