以MacOs sierra0.12.6 为例html
下载地址 https://www.jetbrains.com/idea/download/#section=macpython
Preferences -> Plugins
linux
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install pip
安装pip以后最重要的配置就是配置pip的源,什么是源呢。。。。
就是各类插件的下载地址啦git
mkdir ~/.pip
vi ~/.pip/pip.conf
在pip.conf文件填入下列配置保存就行了github
[global]
index-url = https://pypi.douban.com/simple
楼主这里用的是豆瓣的源
不少文章里面写的index-url = http://pypi.douban.com/simple,这是不对的,如今各大网站都换成了https,哪还有http的,不够安全。
国内的源还有
清华:https://pypi.tuna.tsinghua.edu.cn/simple
阿里云:https://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
华中理工大学:https://pypi.hustunique.com/
山东理工大学:https://pypi.sdutlinux.org/
豆瓣:https://pypi.douban.com/simple/web
sudo pip install Scrapy --upgrade --ignore-installed six
注意(大坑在此)
后面添加的参数必定要加上–upgrade –ignore-installed six
由于mac本身自己就已经安装了six包,可是由于系统安全的缘由,这个包的权限很是高,sudo都不能执行更新,若是执行pip install Scrapy不忽略six包就会报错。安全
DEPRECATION: Uninstalling a distutils installed project (six) has been deprecated and will be removed in a future version.
建立一个Scrapy项目,若是对Scrapy项目不熟悉的小伙伴能够参看Scrapy的文档https://doc.scrapy.org/en/0.16/intro/tutorial.html
这里咱们就使用文档里的介绍来建立一个最简单ruby
scrapy startproject tutorial
使用idea打开tutorial项目
根据官网文档,咱们建立一个最简单的爬虫bash
import scrapy;
class QuotesSpider(scrapy.Spider):
name = "quotes"
def start_requests(self):
urls = [
'http://quotes.toscrape.com/page/1/',
'http://quotes.toscrape.com/page/2/',
]
for url in urls:
yield scrapy.Request(url=url, callback=self.parse)
def parse(self, response):
page = response.url.split("/")[-2]
filename = 'quotes-%s.html' % page
with open(filename, 'wb') as f:
f.write(response.body)
self.log('Saved file %s' % filename)
而后在右上角配置运行环境 Edit Configurations…
Script选择项目的__init__.py
文件
而后修改__init__.py
文件curl
from scrapy import cmdline
cmdline.execute("scrapy crawl quotes".split());
这样idea就跟Scrapy完美结合了,运行,断点debug,代码分析不在话下。这些功能都在右上角这么些个按钮了。各位同窗本身慢慢去试吧。