简单介绍
python下面写爬虫框架。
写爬虫,简单的可以用 requests和BeautifulSoup4库,框架有pyspider和scraypy,
在此假设已经安装好环境
命令
-
scrapy -h # scrapy –help列出命令列表 eg: genspider,runspider, settings , shell
-
scrapy startproject yourprojectname #创建项目
-
scrapy genspider youspidername example.com #在项目下创建一个爬虫程序爬取知道网站
-
scrapy shell # 进入terminal编辑调试
-
scrapy crawl yourspidername #运行爬虫
新建工程
scrapy startproject scrapy3
创建爬虫
scrapy genspider douban250 https://movie.douban.com/top250
运行爬虫
scrapy crawl douban250
中间键
- userAgent 中间键
- ip中间键
注意点
- settings.py 文件里面配置
- USER_AGENT 设置请求头
- 添加一行“FEED_EXPORT_ENCODING = ‘utf-8-sig’” 解决导出中文乱码问题