Python 数据爬取(环境变量)
配置scrapy:
进入setting ——>Project Interpreter——>点击+——>搜索scrapy——>Install Package下载
Anaconda3配置环境变量
1)D:installationBigDatajavaAnaconda3 2)D:installationBigDatajavaAnaconda3Scripts 3)D:installationBigDatajavaAnaconda3Libraryin
准备爬虫
1)使用Anaconda安装Scrapy:
C:UsersTUDOUSI>conda install scrapy
2)在C盘PycharmProjects创建ScrapyDemo
C:UsersTUDOUSIPycharmProjectsScrapyDemoscrapydemo
3)在ScrapyDemo中创建scrapydemo(工程目录)
C:UsersTUDOUSIPycharmProjectsScrapyDemoscrapydemo
4)在scrapydemo下创建scrapy项目
①C:UsersTUDOUSIPycharmProjectsScrapyDemo>scrapy startproject scrapydemo
②C:UsersTUDOUSIPycharmProjectsScrapyDemo>7cd scrapydemo
5)创建Spider(爬虫)
C:UsersTUDOUSIPycharmProjectsScrapyDemoscrapydemo>scrapy genspider demo kgc.cn
6)进入pc——>open——>scrapydemo
Debug爬虫工程
在项目根目录添加脚本文件调用Scrapy框架的命令行执行方法启动爬虫 cmdline模块 execute()方法
from scrapy.cmdline import execute execute(xecrapy crawl example_spider'.split()) (example_spider:你的项目的名称)
这样就可以了哈!