1.安装scrapy
1.1 安装
pip install scrapy
1.2 安装(国内豆瓣)
pip install -i https://pypi.douban.com/simple scrapy
2.配置
2.1 创建项目
在终端输入
scrapy startproject 项目名
cd 项目名
scrapy genspider 爬虫文件名 爬虫域
cd spiders
scrapy crawl 爬虫文件名
2.2 目录结构
2.2 前期准备
在settings.py中
ROBOTSTXT_OBEY = False
DOWNLOAD_DELAY = 3(伪人)
COOKIES_ENABLED = False
USER_AGENT = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36'(防止反爬,设置代理)
在items.py中设置爬取内容
3.获取网页数据
3.1 xpath
在爬虫文件中根据网页结构写明获取数据的xpath
可以用google的xpath helper插件帮助