准备环境:
一、pip list :查看python2.7当前安装哪些包
二、安装必须的包,如存在此步骤略过
lxml:pip install lxml==3.4.2
setuptools
OpenSSL
三、安装scrapy
pip install scrapy
四、pip list:查看需要的包是否安装
注:
windows端安装遇到的问题

图上是由于缺少VCForPython27导致,下载安装即可
2.cmd程序最好以管理员身份运行,以免出现不必要的麻烦
scrapy使用步骤
1.生成项目
scrapy startproject project_name
cd project_name
2.生成代码框架
scrapy genspider example example.com
3编写数据收集方面的代码
4.执行代码
scrapy crwal example
-- coding: utf-8 --import scrapy
class AmoebaSpider(scrapy.Spider):
#name:用于区别不同的Spider,要求唯一 ,也是scrapy genspider Spider1 example.com命令中的 Spider1
name = "amoeba"
allowed_domains = ["amoeba.com"]
#start_urls包含Spider在启动时进行爬取的url列表
start_urls = ( 'http://www.amoeba.com/', )
#spider的一个方法,url下载完成后的Response对象作为唯一参数传给该函数,
# parse方法的功用:
# 1.负责解析返回的数据:
# 2.提取数据(生成Item);
# 3.生成需要进一步处理的Request对象
def parse(self, response):
pass

网友评论