时间:2018年2月21日python
由于时间问题,如下笔记就粗略记录。仅做为我的笔记为用bash
如何安装的细节下面这篇也有介绍,包括如何使用切换虚拟机也有介绍app
http://blog.csdn.net/xshalk/article/details/47301339scrapy
其中如何找 .bash_profile文件
在Finder用快捷键command+shift+G输入打开目录~/
再快捷键:shift+comman+. 显示隐藏文件便可找到这个文件
修改保存以后,再在终端命令行运行 source ~/.bash_profile,就会执行这个文件ide
后来在安装过程遇到一些问题,再通过百度,下面这篇能够解决python路径的问题测试
https://www.jianshu.com/p/2999e258cbf9url
另外,建立不须要任何包的虚拟环境 mkvirtualenv --no-site-packages venvspa
接着步骤就是:workon虚拟环境,pip3 install 一系列包,.net
而后cd进入到须要建立项目的目录下建立项目,命令行
再cd进入项目根目录建立一个爬虫的py文件,
注意,这里下面截图有个小错误:scrapy genspider name url,这里的url不须要“http://”:
而后就是用pycharm来open这个项目,而且要记得从新选择虚拟环境配置,直接就选前面workon选中的虚拟环境。
而后是调试技巧,在scrapy.cfg同级目录下新建main.py文件
而后代码以下:
1 # 经过这个文件来调试,能够提升开发效率 2 3 from scrapy.cmdline import execute 4 5 import sys 6 import os 7 8 ''' 9 设置工程的目录 10 os.path.abspath(__file__) 获取当前文件的目录 11 12 os.path.dirname(file的全路径) 获取当前file的父目录 13 14 打印测试 15 print(os.path.abspath(__file__)) 16 print(os.path.dirname(os.path.abspath(__file__))) 17 18 ''' 19 20 # print(os.path.abspath(__file__)) 21 # print(os.path.dirname(os.path.abspath(__file__))) 22 sys.path.append(os.path.dirname(os.path.abspath(__file__))) 23 24 25 # path = os.path.dirname(os.path.abspath(__file__))+"/ArticleSpider" 26 # sys.path.append(path) 27 # print(sys.path) 28 29 '''执行命令的方法 —— 查询股票名字代码列表''' 30 # execute("scrapy crawl quote_eastmoney_com".split()) 31 32 '''执行命令的方法 —— 查询股票名字代码列表''' 33 execute("scrapy crawl data_eastmoney_com_hsgtcg".split())