-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatom.xml
More file actions
630 lines (521 loc) · 77.3 KB
/
Copy pathatom.xml
File metadata and controls
630 lines (521 loc) · 77.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Light-white's blog</title>
<link href="/atom.xml" rel="self"/>
<link href="http://light-white.me/"/>
<updated>2017-11-09T07:09:17.199Z</updated>
<id>http://light-white.me/</id>
<author>
<name>Light-white</name>
</author>
<generator uri="http://hexo.io/">Hexo</generator>
<entry>
<title>Python函数默认参数</title>
<link href="http://light-white.me/2017/11/09/Python%E5%87%BD%E6%95%B0%E9%BB%98%E8%AE%A4%E5%8F%82%E6%95%B0/"/>
<id>http://light-white.me/2017/11/09/Python函数默认参数/</id>
<published>2017-11-09T02:30:11.000Z</published>
<updated>2017-11-09T07:09:17.199Z</updated>
<content type="html"><![CDATA[<p>之前面试总会被问到这个问题,不过也只知道意思不是很了解内部原理<br>今天来详细的总结一下</p>
<h1 id="Python变量"><a href="#Python变量" class="headerlink" title="Python变量"></a>Python变量</h1><p>首先还是要理解一下python中变量的概念<br>变量来源于数学,是计算机语言中能储存计算结果或能表示值抽象概念<br>Python是一种动态语言 变量并没有固定类型<br>Python中万物皆为对象 变量类似于C的指针 储存对象的地址<br><figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">a = <span class="number">1</span></div></pre></td></tr></table></figure></p>
<p>实际是把1所在地址赋给a<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">>>> id(1)</div><div class="line">1666408672</div><div class="line">>>> a = 1</div><div class="line">>>> id(a)</div><div class="line">1666408672</div></pre></td></tr></table></figure></p>
<p>可以看到 1 和 a 的地址是一样的</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">a = <span class="string">"hello"</span></div></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">>>> id("hello")</div><div class="line">2087305568016</div><div class="line">>>> a = "hello"</div><div class="line">>>> id(a)</div><div class="line">2087305568016</div></pre></td></tr></table></figure>
<p>同理,把”hello”赋值给a之后 a 和 “hello” 的地址相同了</p>
<p>这里有个问题<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line">>>> a = 1</div><div class="line">>>> b = a</div><div class="line">>>> a</div><div class="line">1</div><div class="line">>>> b</div><div class="line">1</div><div class="line">>>> a = 2</div><div class="line">>>> a</div><div class="line">2</div><div class="line">>>> b</div><div class="line">1</div></pre></td></tr></table></figure></p>
<p>为什么 b 还是1呢 因为b = a是把 a 的值赋给 b 也就是把1赋给b<br>a = 2把 a 指向2的地址 b 的还是指向1的地址<br>执行的过程中<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">>>> id(1)</div><div class="line">1666408672</div><div class="line">>>> a = 1</div><div class="line">>>> id(a)</div><div class="line">1666408672</div><div class="line">>>> b = a</div><div class="line">>>> id(b)</div><div class="line">1666408672</div><div class="line">>>> a = 2</div><div class="line">>>> id(a)</div><div class="line">1666408704</div><div class="line">>>> b</div><div class="line">1</div><div class="line">>>> id(b)</div><div class="line">1666408672</div></pre></td></tr></table></figure></p>
<h1 id="Python可变对象和不可变对象"><a href="#Python可变对象和不可变对象" class="headerlink" title="Python可变对象和不可变对象"></a>Python可变对象和不可变对象</h1><p>可变对象就是指创建之后可以进行改变的<br>指的是变量对应内存的值可以被改变<br>不可变对象是不能改变的<br>变量对应内存的值不会被改变<br>我们来看个例子<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">>>> a = a +"1"</div><div class="line">>>> id (a)</div><div class="line">2087305572680</div><div class="line">>>> id("hello")</div><div class="line">2087305568016</div></pre></td></tr></table></figure></p>
<p>还是刚才的 a 里面存的是”hello”,我想在后面加上一个”1”<br>a的地址发生了改变,”hello”的地址没有变化<br>实际上是开了一片新的地址 储存了”hello”+”1”的结果<br>然后让a指向这个地址</p>
<p>可变对象比如list<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">>>> l = []</div><div class="line">>>> id(l)</div><div class="line">2400009794120</div><div class="line">>>> l.append(1)</div><div class="line">>>> l</div><div class="line">[1]</div><div class="line">>>> id(l)</div><div class="line">2400009794120</div></pre></td></tr></table></figure></p>
<p>我们创建了一个list l ,向l中添加了一个元素1<br>l发生了改变 但是他的地址没有变化</p>
<p>Python中可变对象有list dirt<br>Python中不可变对象有int float bool str tuple</p>
<h1 id="Python函数默认参数"><a href="#Python函数默认参数" class="headerlink" title="Python函数默认参数"></a>Python函数默认参数</h1><p>简单介绍下Python的函数<br><figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">def</span> <span class="title">fun</span><span class="params">(n)</span>:</span></div><div class="line"> <span class="keyword">return</span> n * n</div></pre></td></tr></table></figure></p>
<p>一个简单的返回一个数的平方<br>在python中函数也是一个对象 可以复制给变量<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">>>> f = fun</div><div class="line">>>> f(1)</div><div class="line">1</div><div class="line">>>> f(2)</div><div class="line">4</div></pre></td></tr></table></figure></p>
<p>Python中函数可以设置默认参数<br><figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">def</span> <span class="title">fun</span><span class="params">(n=<span class="number">2</span>)</span>:</span></div><div class="line"> <span class="keyword">return</span> n*n</div><div class="line"></div><div class="line">fun() <span class="number">4</span></div><div class="line">fun(<span class="number">1</span>) <span class="number">1</span></div><div class="line">fun(<span class="number">3</span>) <span class="number">9</span></div></pre></td></tr></table></figure></p>
<p>好了 终于到了这里</p>
<p>这是一个之前面试总遇到的问题<br><figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">def</span> <span class="title">fun</span><span class="params">(i,l=[])</span>:</span></div><div class="line"> l.append(i)</div><div class="line"> <span class="keyword">return</span> l</div><div class="line">fun(<span class="number">1</span>)</div><div class="line">fun(<span class="number">4</span>,[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>])</div><div class="line">fun(<span class="number">2</span>)</div></pre></td></tr></table></figure></p>
<p>问下面三条函数的执行结果<br>在理论上我们想要的是<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[1]</div><div class="line">[1,2,3,4]</div><div class="line">[2]</div></pre></td></tr></table></figure></p>
<p>而实际上我们得到的结果是<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[1]</div><div class="line">[1,2,3,4]</div><div class="line">[1,2]</div></pre></td></tr></table></figure></p>
<p>为什么会这样呢</p>
<p>python中函数也是对象 每个函数只会初始化一次<br>l在第一次调用的时候在系统中初始化了一个空的list<br>当我们没有传入参数的时候 l 就指向这个空的list<br>第一次调用结束后这个list变为了[1]<br>第二次我们传入了一个list l 就指向了我们传入的list<br>第三次我们没有传入list l 指向一开始传入的list并且这个list第一次已经添加了一个元素1 继续进行添加 结果是[1,2]</p>
<p>那么怎样避免这种情况呢<br>我们可以把l初始化None<br>把list的初始化放在函数内部<br><figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">def</span> <span class="title">fun</span><span class="params">(i,l=None)</span>:</span></div><div class="line"> <span class="keyword">if</span> l <span class="keyword">is</span> <span class="keyword">None</span>:</div><div class="line"> l = []</div><div class="line"> l.append(i)</div><div class="line"> <span class="keyword">return</span> l</div></pre></td></tr></table></figure></p>
<h1 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h1><p>当我们函数默认参数使用可变参数的时候<br>可变参数会被初始化为一个全局变量 通常我们应当避免这种情况<br>不过有些时候也可以利用这种状况<br><figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">def</span> <span class="title">fun</span><span class="params">(i,cache={})</span>:</span></div><div class="line"> <span class="keyword">if</span> i < <span class="number">2</span>:</div><div class="line"> <span class="keyword">return</span> <span class="number">1</span></div><div class="line"> cache[i] = fun(i<span class="number">-1</span>)+fun(i<span class="number">-2</span>)</div><div class="line"> <span class="keyword">return</span> cache[i]</div></pre></td></tr></table></figure></p>
<p>这样我们就实现了一个简单的带缓存的斐波那契数列</p>
]]></content>
<summary type="html">
<p>之前面试总会被问到这个问题,不过也只知道意思不是很了解内部原理<br>今天来详细的总结一下</p>
<h1 id="Python变量"><a href="#Python变量" class="headerlink" title="Python变量"></a>Python变量<
</summary>
<category term="Python" scheme="http://light-white.me/tags/Python/"/>
</entry>
<entry>
<title>Django+uWSGI+Nginx部署Django</title>
<link href="http://light-white.me/2017/04/07/Django+uWSGI+nginx/"/>
<id>http://light-white.me/2017/04/07/Django+uWSGI+nginx/</id>
<published>2017-04-07T07:58:25.000Z</published>
<updated>2017-04-09T00:09:51.207Z</updated>
<content type="html"><![CDATA[<p>踩了两天的坑终于把Django配好了<br>在这里,我会介绍如何使用uWSGI+Nginx做链接来部署Django项目</p>
<h1 id="环境介绍"><a href="#环境介绍" class="headerlink" title="环境介绍"></a>环境介绍</h1><ul>
<li>Ubuntu 14.04.4 LTS</li>
<li>Python 3.4.3</li>
<li>uWSGI 2.0.15</li>
<li>Nginx 1.4.6</li>
<li>Django 1.11</li>
</ul>
<h1 id="安装uWSGI"><a href="#安装uWSGI" class="headerlink" title="安装uWSGI"></a>安装uWSGI</h1><p>Ubuntu下已经有了python3的版本我们就不多说了<br>使用python3中的pip3安装uWSGI<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">pip3 install uWSGI</div></pre></td></tr></table></figure></p>
<h2 id="测试uWSGI"><a href="#测试uWSGI" class="headerlink" title="测试uWSGI"></a>测试uWSGI</h2><p>新建一个测试文件<code>test.py</code><br><figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line"><span class="comment">#test.py</span></div><div class="line"><span class="function"><span class="keyword">def</span> <span class="title">application</span><span class="params">(env, start_response)</span>:</span></div><div class="line"> start_response(<span class="string">'200 OK'</span>, [(<span class="string">'Content-Type'</span>,<span class="string">'text/html'</span>)])</div><div class="line"> <span class="keyword">return</span> [<span class="string">b"Hello World"</span>]</div></pre></td></tr></table></figure></p>
<p>运行uWSGI<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">uwsgi --http :8000 --wsgi-file test.py</div></pre></td></tr></table></figure></p>
<p>访问<code>127.0.0.1:8000</code><br>网页上显示<code>Hello World</code>,测试成功</p>
<h1 id="安装Nginx"><a href="#安装Nginx" class="headerlink" title="安装Nginx"></a>安装Nginx</h1><p>使用apt-get安装Nginx<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">sudo apt-get install nginx</div></pre></td></tr></table></figure></p>
<h2 id="配置Nginx"><a href="#配置Nginx" class="headerlink" title="配置Nginx"></a>配置Nginx</h2><p>Nginx配置文件在<code>/etc/nginx/nginx.conf</code><br>其中最后两行引入了配置文件<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">include /etc/nginx/conf.d/*.conf;</div><div class="line">include /etc/nginx/sites-enabled/*;</div></pre></td></tr></table></figure></p>
<p>在<code>/etc/nginx/sites-enabled</code>文件夹下有一个<code>default</code><br>将默认的<code>80</code>端口改为一个不常用的端口 这里我改成了8099<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">server {</div><div class="line"> listen 8099 default_server;</div><div class="line"> listen [::]:8099 default_server ipv6only=on;</div><div class="line"></div><div class="line"> root /usr/share/nginx/html;</div><div class="line"> index index.html index.htm;</div><div class="line"></div><div class="line"> server_name localhost;</div><div class="line"></div><div class="line"> location / {</div><div class="line"> try_files $uri $uri/ =404;</div><div class="line"> }</div><div class="line">}</div></pre></td></tr></table></figure></p>
<h1 id="书写配置文件"><a href="#书写配置文件" class="headerlink" title="书写配置文件"></a>书写配置文件</h1><p>在我们的Django项目下要创建一个uwsgi的配置文件,一个Nginx的配置文件还需要一个uwsgi_params文件<br>,该文件可以从<a href="https://github.com/nginx/nginx/blob/master/conf/uwsgi_params" target="_blank" rel="external">uwsgi_params</a>下载</p>
<h2 id="uwsgi配置文件"><a href="#uwsgi配置文件" class="headerlink" title="uwsgi配置文件"></a>uwsgi配置文件</h2><p>在django项目目录下创建demo_uwsgi.ini<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div></pre></td><td class="code"><pre><div class="line">[uwsgi]</div><div class="line"># 对外提供 http 服务的端口</div><div class="line">http = :9000</div><div class="line"></div><div class="line">#the local unix socket file than commnuincate to Nginx 用于和 nginx 进行数据交互的端口</div><div class="line">socket = 127.0.0.1:8001</div><div class="line"></div><div class="line"># the base directory (full path) django 程序的主目录</div><div class="line">chdir = /home/django/demo</div><div class="line"></div><div class="line"># Django's wsgi file</div><div class="line">wsgi-file = demo/wsgi.py</div><div class="line"></div><div class="line"># maximum number of worker processes</div><div class="line">processes = 4</div><div class="line"></div><div class="line">#thread numbers startched in each worker process</div><div class="line">threads = 2</div><div class="line"></div><div class="line">#monitor uwsgi status 通过该端口可以监控 uwsgi 的负载情况</div><div class="line">stats = 127.0.0.1:9191</div><div class="line"></div><div class="line"># clear environment on exit</div><div class="line">vacuum = true</div><div class="line"></div><div class="line"># 后台运行,并输出日志</div><div class="line">daemonize = /var/log/uwsgi.log</div></pre></td></tr></table></figure></p>
<p>启动uwsgi<code>uwsgi demo_uwsgi.ini</code></p>
<h2 id="Nginx配置文件"><a href="#Nginx配置文件" class="headerlink" title="Nginx配置文件"></a>Nginx配置文件</h2><p>在django项目目录下创建<code>django-nginx.conf</code><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div></pre></td><td class="code"><pre><div class="line"># the upstream component nginx needs to connect to</div><div class="line">upstream django {</div><div class="line"> # server unix:///path/to/your/mysite/mysite.sock; # for a file socket</div><div class="line"> server 127.0.0.1:8001; # 与uwsgi通信端口</div><div class="line">}</div><div class="line"></div><div class="line"># configuration of the server</div><div class="line">server {</div><div class="line"> # 对外监听端口</div><div class="line"> listen 80;</div><div class="line"> # the domain name it will serve for</div><div class="line"> server_name 112.74.58.180; # substitute your machine's IP address or FQDN</div><div class="line"> charset utf-8;</div><div class="line"></div><div class="line"> # max upload size</div><div class="line"> client_max_body_size 75M; # adjust to taste</div><div class="line"></div><div class="line"> # Django media</div><div class="line"> location /media {</div><div class="line"> alias /path/to/your/mysite/media;</div><div class="line"> }</div><div class="line"></div><div class="line"> location /static {</div><div class="line"> alias /home/django/demo/static;</div><div class="line"> }</div><div class="line"></div><div class="line"> # Finally, send all non-media requests to the Django server.</div><div class="line"> location / {</div><div class="line"> uwsgi_pass django;</div><div class="line"> include /home/django/demo/uwsgi_params;</div><div class="line"> }</div><div class="line">}</div></pre></td></tr></table></figure></p>
<p>写完配置文件,要将配置文件链接到Nginx下<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">sudo ln -s /home/django/demo/django_nginx.conf /etc/nginx/sites-enabled/</div></pre></td></tr></table></figure></p>
<h2 id="Django-配置"><a href="#Django-配置" class="headerlink" title="Django 配置"></a>Django 配置</h2><p>在django项目下的settings.py中添加<br><code>ALLOWED_HOSTS = ['本机ip','127.0.0.1','localhost']</code><br>关于静态文件的处理方法请看我的前一篇博客 <a href="/2017/04/07/Django1.10静态文件/" title="Django 1.10 静态资源配置">Django 1.10 静态资源配置</a><br>然后在项目目录下执行<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">python3 manage.py collectstatic</div></pre></td></tr></table></figure></p>
<h1 id="最终测试"><a href="#最终测试" class="headerlink" title="最终测试"></a>最终测试</h1><p>执行<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">nginx -s reload</div><div class="line">uwsgi --ini /home/django/demo/demo_uwsgi.ini</div></pre></td></tr></table></figure></p>
<h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p>其中主要踩坑的地方有</p>
<ol>
<li>Nginx的默认端口修改</li>
<li>uwsgi配置中http端口并不是访问用的端口</li>
<li>Django静态文件要用<code>python3 manage.py collectstatic</code>收集</li>
</ol>
]]></content>
<summary type="html">
<p>踩了两天的坑终于把Django配好了<br>在这里,我会介绍如何使用uWSGI+Nginx做链接来部署Django项目</p>
<h1 id="环境介绍"><a href="#环境介绍" class="headerlink" title="环境介绍"></a>环境介绍</h
</summary>
<category term="Python" scheme="http://light-white.me/tags/Python/"/>
<category term="Django" scheme="http://light-white.me/tags/Django/"/>
<category term="Nginx" scheme="http://light-white.me/tags/Nginx/"/>
<category term="uWSGI" scheme="http://light-white.me/tags/uWSGI/"/>
</entry>
<entry>
<title>Django 1.10 静态资源配置</title>
<link href="http://light-white.me/2017/04/07/Django1.10%E9%9D%99%E6%80%81%E6%96%87%E4%BB%B6/"/>
<id>http://light-white.me/2017/04/07/Django1.10静态文件/</id>
<published>2017-04-07T05:19:59.000Z</published>
<updated>2017-04-07T05:41:16.726Z</updated>
<content type="html"><![CDATA[<h1 id="1-Django项目结构"><a href="#1-Django项目结构" class="headerlink" title="1. Django项目结构"></a>1. Django项目结构</h1><pre><code>Project/
│ db.sqlite3
│ happy_uwsgi.ini
│ manage.py
├─Project
│ │ settings.py
│ │ urls.py
│ │ wsgi.py
│ │ __init__.py
├─index
│ │ admin.py
│ │ apps.py
│ │ models.py
│ │ tests.py
│ │ urls.py
│ │ views.py
│ │ __init__.py
│ ├─migrations
│ ├─static
│ │ ├─css
│ │ ├─js
│ ├─templates
│ │ index.html
└─templates
</code></pre><p>Project是我的项目名,index是我的一个app名<br>首先,要在我们的app目录下创建两个文件夹<code>templates</code>和<code>static</code><br><code>templates</code>用来存放我们的模板html,<code>static</code>用来存放我们的静态资源</p>
<h1 id="2-修改settings-py"><a href="#2-修改settings-py" class="headerlink" title="2. 修改settings.py"></a>2. 修改settings.py</h1><p>在配置文件的最后,我们会找到<code>STATIC_URL = '/static/'</code><br>在它的下一行我们添加一行<code>STATIC_ROOT = os.path.join(BASE_DIR, 'static')</code>,然后保存</p>
<h1 id="3-修改urls-py"><a href="#3-修改urls-py" class="headerlink" title="3. 修改urls.py"></a>3. 修改urls.py</h1><p>在项目名<code>Project</code>下的urls.py中导入两个库<br><figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">from</span> django.conf <span class="keyword">import</span> settings</div><div class="line"><span class="keyword">from</span> django.conf.urls.static <span class="keyword">import</span> static</div></pre></td></tr></table></figure></p>
<p>在末尾追加<code>+ static(settings.STATIC_URL, document_root = settings.STATIC_ROOT)</code></p>
<p>完整的urls.py如下<br><figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">from</span> django.conf.urls <span class="keyword">import</span> url,include</div><div class="line"><span class="keyword">from</span> django.contrib <span class="keyword">import</span> admin</div><div class="line"><span class="keyword">from</span> django.conf <span class="keyword">import</span> settings</div><div class="line"><span class="keyword">from</span> django.conf.urls.static <span class="keyword">import</span> static</div><div class="line"></div><div class="line">urlpatterns = [</div><div class="line"> url(<span class="string">r'^$'</span>, include(<span class="string">'index.urls'</span>)),</div><div class="line"> url(<span class="string">r'^admin/'</span>, admin.site.urls),</div><div class="line">] + static(settings.STATIC_URL, document_root = settings.STATIC_ROOT)</div></pre></td></tr></table></figure></p>
<h1 id="4-修改静态引用"><a href="#4-修改静态引用" class="headerlink" title="4. 修改静态引用"></a>4. 修改静态引用</h1><p>在网页中所有的静态文件引用前要加上<code>/static/</code><br><figure class="highlight html"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="tag"><<span class="name">link</span> <span class="attr">rel</span>=<span class="string">"stylesheet"</span> <span class="attr">href</span>=<span class="string">"/static/css/style.css"</span> <span class="attr">type</span>=<span class="string">"text/css"</span> /></span></div><div class="line"><span class="tag"><<span class="name">script</span> <span class="attr">src</span>=<span class="string">"/static/js/index.js"</span>></span><span class="undefined"></span><span class="tag"></<span class="name">script</span>></span></div></pre></td></tr></table></figure></p>
]]></content>
<summary type="html">
<h1 id="1-Django项目结构"><a href="#1-Django项目结构" class="headerlink" title="1. Django项目结构"></a>1. Django项目结构</h1><pre><code>Project/
│ db.sqlit
</summary>
<category term="Python" scheme="http://light-white.me/tags/Python/"/>
<category term="Django" scheme="http://light-white.me/tags/Django/"/>
</entry>
<entry>
<title>使用Scrapy抓取链家网租房信息</title>
<link href="http://light-white.me/2017/03/15/%E4%BD%BF%E7%94%A8Scrapy%E6%8A%93%E5%8F%96%E9%93%BE%E5%AE%B6%E7%BD%91%E7%A7%9F%E6%88%BF%E4%BF%A1%E6%81%AF/"/>
<id>http://light-white.me/2017/03/15/使用Scrapy抓取链家网租房信息/</id>
<published>2017-03-15T05:54:13.000Z</published>
<updated>2017-03-26T08:42:31.539Z</updated>
<content type="html"><![CDATA[<h1 id="1-Scrapy介绍"><a href="#1-Scrapy介绍" class="headerlink" title="1. Scrapy介绍"></a>1. Scrapy介绍</h1><p>Scrapy,Python开发的一个快速,高层次的屏幕抓取和web抓取框架,用于抓取web站点并从页面中提取结构化的数据。<br>Scrapy吸引人的地方在于它是一个框架,任何人都可以根据需求方便的修改。<br>Scratch,是抓取的意思,这个Python的爬虫框架叫Scrapy,大概也是这个意思吧,就叫它:小刮刮吧。<br>Scrapy的官方网站:<a href="https://scrapy.org/" target="_blank" rel="external">https://scrapy.org/</a><br>关于Scrapy的安装可以看我之前的博客 <a href="http://light-white.me/2017/02/06/Windows%E4%B8%8BPython%E7%88%AC%E8%99%AB%E6%A1%86%E6%9E%B6Scrapy%E5%AE%89%E8%A3%85/">Windows下Python爬虫框架Scrapy安装</a> </p>
<h1 id="2-创建爬虫项目"><a href="#2-创建爬虫项目" class="headerlink" title="2. 创建爬虫项目"></a>2. 创建爬虫项目</h1><p>在控制台执行<br><code>scrapy startproject myspider</code><br>目录结构如下: </p>
<pre><code>└─myspider
│ scrapy.cfg
└─myspider
│ items.py
│ middlewares.py
│ pipelines.py
│ settings.py
│ __init__.py
├─spiders
│ │ __init__.py
│ └─__pycache__
└─__pycache__
</code></pre><h1 id="3-编写爬虫"><a href="#3-编写爬虫" class="headerlink" title="3.编写爬虫"></a>3.编写爬虫</h1><p>在spiders目录下 新建<code>lianjia_spiders.py</code><br><figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div></pre></td><td class="code"><pre><div class="line"><span class="comment"># -*- coding: utf-8 -*-</span></div><div class="line"><span class="keyword">import</span> scrapy</div><div class="line"><span class="keyword">import</span> re</div><div class="line"></div><div class="line"><span class="keyword">from</span> scrapy.selector <span class="keyword">import</span> Selector</div><div class="line"><span class="keyword">from</span> scrapy.http <span class="keyword">import</span> Request</div><div class="line"><span class="keyword">from</span> lianjia.items <span class="keyword">import</span> LianjiaItem</div><div class="line"><span class="keyword">from</span> scrapy.spiders <span class="keyword">import</span> CrawlSpider, Rule</div><div class="line"><span class="keyword">from</span> scrapy.linkextractors <span class="keyword">import</span> LinkExtractor</div><div class="line"></div><div class="line"><span class="class"><span class="keyword">class</span> <span class="title">LianjiaSpider</span><span class="params">(CrawlSpider)</span>:</span></div><div class="line"> name = <span class="string">'lianjia'</span></div><div class="line"> allowed_domains = [<span class="string">'lianjia.com'</span>]</div><div class="line"> rules = (</div><div class="line"> Rule(LinkExtractor(allow=(<span class="string">r'^http://bj.lianjia.com/zufang/BJ[0-9]{10}'</span>, )), callback=<span class="string">'parse_item'</span>,follow=<span class="keyword">True</span>),</div><div class="line"> Rule(LinkExtractor(allow=(<span class="string">r'^http://bj.lianjia.com/zufang/[0-9]{12}'</span>, )), callback=<span class="string">'parse_item'</span>,follow=<span class="keyword">True</span>),</div><div class="line"> )</div><div class="line"></div><div class="line"> <span class="function"><span class="keyword">def</span> <span class="title">start_requests</span><span class="params">(self)</span>:</span></div><div class="line"> <span class="keyword">yield</span> scrapy.Request(<span class="string">'http://bj.lianjia.com/zufang/'</span>)</div><div class="line"> <span class="keyword">for</span> i <span class="keyword">in</span> range(<span class="number">2</span>,<span class="number">101</span>):</div><div class="line"> <span class="keyword">yield</span> scrapy.Request(<span class="string">'http://bj.lianjia.com/zufang/pg%d/'</span>%i)</div><div class="line"></div><div class="line"> <span class="function"><span class="keyword">def</span> <span class="title">parse_item</span><span class="params">(self, response)</span>:</span></div><div class="line"> print(<span class="string">"-----parse_item-----"</span>)</div><div class="line"> selector = Selector(response)</div><div class="line"> item = LianjiaItem()</div><div class="line"> item[<span class="string">'title'</span>] = selector.xpath(<span class="string">'/html/body/div[4]/div[1]/div/div[1]/h1/text()'</span>).extract_first()</div><div class="line"> item[<span class="string">'area'</span>] = selector.xpath(<span class="string">'/html/body/div[4]/div[2]/div[2]/div[2]/p[1]/text()'</span>).extract_first()</div><div class="line"> item[<span class="string">'price'</span>] = selector.xpath(<span class="string">'/html/body/div[4]/div[2]/div[2]/div[1]/span[1]/text()'</span>).extract_first()</div><div class="line"> regex = selector.xpath(<span class="string">'/html/body/script[12]/text()'</span>).extract()</div><div class="line"> position = re.search(<span class="string">'resblockPosition:(.+),'</span>,regex.pop())</div><div class="line"> item[<span class="string">'position'</span>] = position.group()[:<span class="number">-1</span>].split(<span class="string">':'</span>)[<span class="number">1</span>]</div><div class="line"> item[<span class="string">'url'</span>] = response.url</div><div class="line"> <span class="keyword">return</span> item</div></pre></td></tr></table></figure></p>
<p>其中我们要编写一个类继承<code>scrapy.spiders</code>,不过这里我使用的<code>CrawlSpider</code>来做全站爬取<br>其中<code>name</code>是用来标识一个爬虫,名字唯一<br><code>allowed_domains</code>是允许爬虫爬取的域<br>其中还应该包含一个<code>start_urls</code>作为爬虫爬取的初始页面<br>不过这里我使用<code>start_requests</code>来生成爬取列表了<br><code>rules</code>是<code>CrawlSpider</code>中的属性,用来匹配当前页面中的链接 </p>
<h1 id="4-items"><a href="#4-items" class="headerlink" title="4.items"></a>4.items</h1><p>items.py中我们编写要抓取的对象信息<br>每次爬取页面都会返回一个item<br><figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">import</span> scrapy</div><div class="line"></div><div class="line"><span class="class"><span class="keyword">class</span> <span class="title">LianjiaItem</span><span class="params">(scrapy.Item)</span>:</span></div><div class="line"> <span class="comment"># define the fields for your item here like:</span></div><div class="line"> id = scrapy.Field() <span class="comment">#存入数据库的id</span></div><div class="line"> title = scrapy.Field() <span class="comment">#房屋页面的标题</span></div><div class="line"> area = scrapy.Field() <span class="comment">#房屋的面积</span></div><div class="line"> price = scrapy.Field() <span class="comment">#每月房租</span></div><div class="line"> position = scrapy.Field() <span class="comment">#房屋的经纬度信息</span></div><div class="line"> url = scrapy.Field() <span class="comment">#网址</span></div></pre></td></tr></table></figure></p>
<h1 id="5-Selector选择器"><a href="#5-Selector选择器" class="headerlink" title="5.Selector选择器"></a>5.Selector选择器</h1><p>我们要从页面中抓取数据,需要解析当前HTML页面<br>Scrapy中自带了选择器,可以选择由XPath或CSS表达式指定的部分<br>在这里我使用XPath进行界面的解析,在爬虫中可以看到<br><code>selector.xpath('/html/body/div[4]/div[2]/div[2]/div[2]/p[1]/text()').extract().pop()</code><br><code>.extract_first()</code>是返回内容List中的第一个<br>在爬虫中每次都会创建一个item将抓取到的数据存入item 最后函数会返回一个item</p>
<h1 id="6-Item-pipelines"><a href="#6-Item-pipelines" class="headerlink" title="6.Item pipelines"></a>6.Item pipelines</h1><p>爬虫中返回的Item,都进入到pipelines进行处理<br><figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">import</span> json</div><div class="line"><span class="keyword">import</span> codecs</div><div class="line"><span class="keyword">import</span> pymongo</div><div class="line"></div><div class="line"><span class="class"><span class="keyword">class</span> <span class="title">LianjiaPipeline</span><span class="params">(object)</span>:</span></div><div class="line"></div><div class="line"> collection_name = <span class="string">'lianjia_items'</span></div><div class="line"></div><div class="line"> <span class="function"><span class="keyword">def</span> <span class="title">__init__</span><span class="params">(self, mongo_uri, mongo_db)</span>:</span></div><div class="line"> self.mongo_uri = mongo_uri</div><div class="line"> self.mongo_db = mongo_db</div><div class="line"></div><div class="line"><span class="meta"> @classmethod</span></div><div class="line"> <span class="function"><span class="keyword">def</span> <span class="title">from_crawler</span><span class="params">(cls, crawler)</span>:</span></div><div class="line"> <span class="keyword">return</span> cls(</div><div class="line"> mongo_uri=crawler.settings.get(<span class="string">'MONGO_URI'</span>),</div><div class="line"> mongo_db=crawler.settings.get(<span class="string">'MONGO_DATABASE'</span>)</div><div class="line"> )</div><div class="line"></div><div class="line"> <span class="function"><span class="keyword">def</span> <span class="title">open_spider</span><span class="params">(self, spider)</span>:</span></div><div class="line"> self.client = pymongo.MongoClient(self.mongo_uri)</div><div class="line"> self.db = self.client[self.mongo_db]</div><div class="line"></div><div class="line"> <span class="function"><span class="keyword">def</span> <span class="title">close_spider</span><span class="params">(self, spider)</span>:</span></div><div class="line"> self.client.close()</div><div class="line"></div><div class="line"> <span class="function"><span class="keyword">def</span> <span class="title">process_item</span><span class="params">(self, item, spider)</span>:</span></div><div class="line"> self.db[self.collection_name].insert(dict(item))</div><div class="line"> <span class="keyword">return</span> item</div></pre></td></tr></table></figure></p>
<p>其中必须有<code>process_item</code>来处理爬虫返回的item<br><code>__init__</code>初始化方法<br><code>from_crawler</code>用来读取当前爬虫配置<br><code>open_spider</code>爬虫打开时调用,在此进行数据库链接<br><code>close_spider</code>爬虫关闭时调用,在此关闭数据库链接 </p>
<h1 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h1><p>在最外层目录外使用命令行执行<code>scrapy crawl lianjia</code><br>其中<code>lianjia</code>是我在爬虫中设定的<code>name</code><br>简单的进行了试验,要关闭Scrapy的<code>ROBOTSTXT_OBEY = False</code><br>今天成功的爬取了2620条数据没有被封ip<br>github:<a href="https://github.com/light-white/lianjia_scrapy" target="_blank" rel="external">lianjia_scrapy</a></p>
]]></content>
<summary type="html">
<h1 id="1-Scrapy介绍"><a href="#1-Scrapy介绍" class="headerlink" title="1. Scrapy介绍"></a>1. Scrapy介绍</h1><p>Scrapy,Python开发的一个快速,高层次的屏幕抓取和web抓取框
</summary>
<category term="Python" scheme="http://light-white.me/tags/Python/"/>
<category term="Scrapy" scheme="http://light-white.me/tags/Scrapy/"/>
<category term="MongoDB" scheme="http://light-white.me/tags/MongoDB/"/>
</entry>
<entry>
<title>百度Ueditor图片管理无法显示</title>
<link href="http://light-white.me/2017/02/17/baidu/"/>
<id>http://light-white.me/2017/02/17/baidu/</id>
<published>2017-02-17T07:03:48.000Z</published>
<updated>2017-02-17T07:28:05.518Z</updated>
<content type="html"><![CDATA[<p>今天在使用ueditor做新闻编辑时出现一点问题,图片上传之后后台管理界面获取不到<br><img src="http://7xtgk5.com1.z0.glb.clouddn.com/ueditor_imagemanage.png" alt=""><br>打开控制台发现获取的是本地绝对路径</p>
<p>第一时间想到修改<code>config.json</code>中的文件访问路径</p>
<pre><code>/* 列出指定目录下的图片 */
"imageManagerActionName": "listimage", /* 执行图片管理的action名称 */
"imageManagerListPath": "/ueditor/jsp/upload/image/", /* 指定要列出图片的目录 */
"imageManagerListSize": 20, /* 每次列出文件数量 */
"imageManagerUrlPrefix": "http://localhost:8080/Meet/", /* 图片访问路径前缀 */
"imageManagerInsertAlign": "none", /* 插入的图片浮动方式 */
"imageManagerAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 列出的文件类型 */
</code></pre><p>将UrlPrefix修改为当前项目域名<br>然后发现还有问题 这时候绝对路径跟在域名后面了<br>配置文件<code>ueditor.config.js</code>中说<code>controller.jsp</code>是服务器统一请求接口路径<br>我们修改一下他试试<br>修改后代码如下 </p>
<pre><code><%@ page language="java" contentType="text/html; charset=UTF-8"
import="com.baidu.ueditor.ActionEnter"
pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<%
request.setCharacterEncoding( "utf-8" );
response.setHeader("Content-Type" , "text/html");
String rootPath = application.getRealPath( "/" );
String action = request.getParameter("action");
String result = new ActionEnter( request, rootPath ).exec();
if( action!=null &&
(action.equals("listfile") || action.equals("listimage") ) ){
rootPath = rootPath.replace("\\", "/");
result = result.replaceAll(rootPath, "/");
}
out.write( result );
%>
</code></pre><p>这时就能看到上传到服务器上的图片与文件了</p>
]]></content>
<summary type="html">
<p>今天在使用ueditor做新闻编辑时出现一点问题,图片上传之后后台管理界面获取不到<br><img src="http://7xtgk5.com1.z0.glb.clouddn.com/ueditor_imagemanage.png" alt=""><br>打开控制台发现获
</summary>
<category term="ueditor" scheme="http://light-white.me/tags/ueditor/"/>
<category term="html" scheme="http://light-white.me/tags/html/"/>
<category term="jsp" scheme="http://light-white.me/tags/jsp/"/>
</entry>
<entry>
<title>Windows下Python爬虫框架Scrapy安装</title>
<link href="http://light-white.me/2017/02/06/Windows%E4%B8%8BPython%E7%88%AC%E8%99%AB%E6%A1%86%E6%9E%B6Scrapy%E5%AE%89%E8%A3%85/"/>
<id>http://light-white.me/2017/02/06/Windows下Python爬虫框架Scrapy安装/</id>
<published>2017-02-06T05:57:36.000Z</published>
<updated>2017-02-06T07:10:39.395Z</updated>
<content type="html"><![CDATA[<h1 id="1-Scrapy介绍"><a href="#1-Scrapy介绍" class="headerlink" title="1. Scrapy介绍"></a>1. Scrapy介绍</h1><p>Scrapy,Python开发的一个快速,高层次的屏幕抓取和web抓取框架,用于抓取web站点并从页面中提取结构化的数据。<br>Scrapy吸引人的地方在于它是一个框架,任何人都可以根据需求方便的修改。<br>Scratch,是抓取的意思,这个Python的爬虫框架叫Scrapy,大概也是这个意思吧,就叫它:小刮刮吧。<br>Scrapy的官方网站:<a href="https://scrapy.org/" target="_blank" rel="external">https://scrapy.org/</a> </p>
<h1 id="2-Python安装"><a href="#2-Python安装" class="headerlink" title="2. Python安装"></a>2. Python安装</h1><p>这步不用说了吧 没有Python怎么用Scrapy<br>Python的官方网站:<a href="https://www.python.org/" target="_blank" rel="external">https://www.python.org/</a><br>我现在使用的是python3.6<br>安装完python记得在控制台输入python,进入python命令行 成功</p>
<h1 id="3-pip包管理器"><a href="#3-pip包管理器" class="headerlink" title="3. pip包管理器"></a>3. pip包管理器</h1><p>pip是python中很好用的包管理器,我们将使用它来安装我们的Scrapy框架<br>pip的下载地址:<a href="https://pypi.python.org/pypi/pip" target="_blank" rel="external">https://pypi.python.org/pypi/pip</a><br><img src="http://7xtgk5.com1.z0.glb.clouddn.com/python_pip.png" alt=""><br>我们下载下面<code>.tar.gz</code>压缩包,下载完成后解压到一个文件夹<br>在控制台下输入 </p>
<pre><code>python setup.py install
</code></pre><p>安装完成后在控制台下输入pip显示出帮助信息 安装完成</p>
<h1 id="4-安装Scrapy"><a href="#4-安装Scrapy" class="headerlink" title="4. 安装Scrapy"></a>4. 安装Scrapy</h1><p>在控制台下输入 </p>
<pre><code>pip install scrapy
</code></pre><p>这时候可能会遇到依赖包安装失败<br>这时候我们在这个网站手动下载依赖包<br><a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/" target="_blank" rel="external">http://www.lfd.uci.edu/~gohlke/pythonlibs/</a><br>例如<code>lxml‑3.7.2‑cp36‑cp36m‑win32.whl</code>中<code>cp36</code>指的是python3.6版本,后面<code>win32</code>指32位程序<br>大家根据自己的python版本进行选择<br>下载到本地之后,使用pip进行安装 </p>
<pre><code>pip install 文件全名
</code></pre><p>例如 </p>
<pre><code>pip install lxml‑3.7.2‑cp36‑cp36m‑win32.whl
</code></pre><h1 id="5-创建Scrapy项目"><a href="#5-创建Scrapy项目" class="headerlink" title="5. 创建Scrapy项目"></a>5. 创建Scrapy项目</h1><p>在控制台中输入 </p>
<pre><code>scrapy startproject 项目名
</code></pre><p>就在当前文件夹下生成scrapy项目</p>
]]></content>
<summary type="html">
<h1 id="1-Scrapy介绍"><a href="#1-Scrapy介绍" class="headerlink" title="1. Scrapy介绍"></a>1. Scrapy介绍</h1><p>Scrapy,Python开发的一个快速,高层次的屏幕抓取和web抓取框
</summary>
<category term="Python" scheme="http://light-white.me/tags/Python/"/>
<category term="Windows" scheme="http://light-white.me/tags/Windows/"/>
<category term="Scrapy" scheme="http://light-white.me/tags/Scrapy/"/>
</entry>
<entry>
<title>Windows环境下Mongodb安装及配置</title>
<link href="http://light-white.me/2016/10/27/Windows%E7%8E%AF%E5%A2%83%E4%B8%8BMongodb%E5%AE%89%E8%A3%85%E5%8F%8A%E9%85%8D%E7%BD%AE/"/>
<id>http://light-white.me/2016/10/27/Windows环境下Mongodb安装及配置/</id>
<published>2016-10-27T10:32:32.000Z</published>
<updated>2016-10-27T10:32:53.380Z</updated>
<content type="html"><![CDATA[<h1 id="1-MongoDB介绍"><a href="#1-MongoDB介绍" class="headerlink" title="1. MongoDB介绍"></a>1. MongoDB介绍</h1><p>MongoDB 是由C++语言编写的,是一个基于分布式文件存储的开源数据库系统。<br>在高负载的情况下,添加更多的节点,可以保证服务器性能。<br>MongoDB 旨在为WEB应用提供可扩展的高性能数据存储解决方案。<br>MongoDB 将数据存储为一个文档,数据结构由键值(key=>value)对组成。<br>MongoDB 文档类似于 JSON 对象。字段值可以包含其他文档,数组及文档数组。<br>MongoDB的官方网站: <a href="https://www.mongodb.com/" target="_blank" rel="external">https://www.mongodb.com/</a></p>
<h1 id="2-下载安装包"><a href="#2-下载安装包" class="headerlink" title="2. 下载安装包"></a>2. 下载安装包</h1><p>打开MongoDB官方网站点击Download,下载合适的msi安装包<br>我这里下载的3.2.1版本的<a href="https://www.mongodb.com/download-center?jmp=nav#community" target="_blank" rel="external">mongodb-win32-x86_64-2008plus-ssl-3.2.10-signed.msi</a> </p>
<h1 id="3-安装MongoDB"><a href="#3-安装MongoDB" class="headerlink" title="3.安装MongoDB"></a>3.安装MongoDB</h1><p>双击安装包,开始安装,同意协议<br>注意这一步,选择这一项<br><img src="http://7xtgk5.com1.z0.glb.clouddn.com//winMongo/Mongodb%20install.png" alt=""><br>点击上面的会直接进入安装<br><img src="http://7xtgk5.com1.z0.glb.clouddn.com/winMongo/Mongodb%20location%20.png" alt=""><br>我们在这里修改MongoDB的安装路径,这里我选择了安装到D盘<br>接下来就直接安装就可以了</p>
<h2 id="3-1配置MongoDB"><a href="#3-1配置MongoDB" class="headerlink" title="3.1配置MongoDB"></a>3.1配置MongoDB</h2><p>安装完成后,我们需要对MongoDB进行一系列的配置<br>最基本的我们要为MongoDB指定数据库的存放路径<br>我在我的MongoDB目录D:\MongoDB下新建一个data目录<br>在data目录下创建db目录作为MongoDB数据库的存放路径<br>创建Logs目录作为日志文件夹<br>在命令行下,我们进入之前安装的MongoDB的bin目录下,执行 </p>
<pre><code>mongod --dbpath d:\MongoDB\data\db
</code></pre><p>最后显示</p>
<pre><code>2016-10-27T09:23:20.055+0800 I NETWORK [initandlisten] waiting for connections on port 27017
</code></pre><p>表示启动成功,我们可以在浏览器输入<a href="http://localhost:27017/" target="_blank" rel="external">http://localhost:27017/</a><br><img src="http://7xtgk5.com1.z0.glb.clouddn.com/winMongo/Mongodb%20port.png" alt=""><br>现在就可以算初步配置完成</p>
<h1 id="4-MongoDB安装Windows服务"><a href="#4-MongoDB安装Windows服务" class="headerlink" title="4.MongoDB安装Windows服务"></a>4.MongoDB安装Windows服务</h1><p>我们要将MongoDB安装为Windows服务,首先要通过管理员权限启动cmd,进入bin目录下,执行</p>
<pre><code>mongod --dbpath "d:\MongoDB\data\db" --logpath "d:\MongoDB\data\logs\MongoDB.log" --logappend --install
</code></pre><p>–dbpath 设置数据库路径<br>–logpath 设置log日志文件<br>–logappend 使用追加的方式写日志 </p>
<p>接下来我们就可以使用</p>
<pre><code>net start MongoDB
</code></pre><p>来启动服务</p>
<p>如果我们想删除MongoDB服务的话,在bin目录下执行</p>
<pre><code>mongod.exe --remove --serviceName "MongoDB"
</code></pre><p>就可以删除MongoDB的服务了</p>
<h1 id="5-编写配置文件"><a href="#5-编写配置文件" class="headerlink" title="5.编写配置文件"></a>5.编写配置文件</h1><p>我们已经可以运行MongoDB服务了<br>但是敲这么长的命令也很麻烦,这时候我们可以编写一个MongoDB的配置文件,使用配置文件来安装MongoDB服务<br>我们继续在\data目录下新建etc目录,在etc目录下创建mongod.conf<br>我门打开mongod.conf 书写配置信息 目前MongoDB配置文件语法使用<a href="http://www.yaml.org/" target="_blank" rel="external">YAML</a></p>
<pre><code>systemLog:
destination: file
path: D:\MongoDB\data\logs\MongoDB.log #log日志文件路径
logAppend : true #log日志追加模式,不开启这个的话,重启服务会覆盖上次的log文件
net:
port: 27017 #端口号 默认为27017
storage:
dbPath: D:\MongoDB\data\db #数据库路径
</code></pre><p>然后使用配置文件启动MongoDB</p>
<pre><code>mongod --config d:\MongoDB\data\etc\mongod.conf
</code></pre><p>打开<a href="http://localhost:27017/" target="_blank" rel="external">http://localhost:27017/</a>查看是否启动成功</p>
<p>详细的配置文件写法请参照<a href="https://docs.mongodb.com/manual/reference/configuration-options/" target="_blank" rel="external">Configuration File Options</a></p>
<p>我门现在可以使用config来创建MongoDB服务,使用管理员权限启动cmd,进入\bin目录</p>
<pre><code>mongod --config d:\MongoDB\data\etc\mongod.conf --install
</code></pre><p>右键我的电脑->管理->服务和应用程序->服务<br><img src="http://7xtgk5.com1.z0.glb.clouddn.com/winMongo/Mongodb%20service.png" alt=""><br>可以看到我们的MongoDB服务已经运行 </p>
<p>到此MongoDB的安装就已经结束,为大家推荐一款MongoDB可视化工具<a href="http://mongobooster.com/" target="_blank" rel="external">mongobooster</a><br><img src="http://7xtgk5.com1.z0.glb.clouddn.com/winMongo/Mongobooster.com.png" alt=""><br><img src="http://7xtgk5.com1.z0.glb.clouddn.com/winMongo/Mongobooster.png" alt=""></p>
]]></content>
<summary type="html">
<h1 id="1-MongoDB介绍"><a href="#1-MongoDB介绍" class="headerlink" title="1. MongoDB介绍"></a>1. MongoDB介绍</h1><p>MongoDB 是由C++语言编写的,是一个基于分布式文件存储的
</summary>
<category term="Windows" scheme="http://light-white.me/tags/Windows/"/>
<category term="MongoDB" scheme="http://light-white.me/tags/MongoDB/"/>
</entry>
<entry>
<title>Markdown语法简介</title>
<link href="http://light-white.me/2016/09/23/Markdown%E8%AF%AD%E6%B3%95%E7%AE%80%E4%BB%8B/"/>
<id>http://light-white.me/2016/09/23/Markdown语法简介/</id>
<published>2016-09-23T07:51:04.000Z</published>
<updated>2017-02-06T07:10:46.440Z</updated>
<content type="html"><![CDATA[<h1 id="1-Markdown概述"><a href="#1-Markdown概述" class="headerlink" title="1. Markdown概述"></a>1. Markdown概述</h1><p><strong>宗旨</strong></p>
<p>Markdown 的目标是实现「易读易写」。</p>
<p>可读性,无论如何,都是最重要的。一份使用 Markdown 格式撰写的文件应该可以直接以纯文本发布,并且看起来不会像是由许多标签或是格式指令所构成。Markdown 语法受到一些既有 text-to-HTML 格式的影响,包括 Setext、atx、Textile、reStructuredText、Grutatext 和 EtText,而最大灵感来源其实是纯文本电子邮件的格式。</p>
<p>总之, Markdown 的语法全由一些符号所组成,这些符号经过精挑细选,其作用一目了然。比如:在文字两旁加上星号,看起来就像*强调*。Markdown 的列表看起来,嗯,就是列表。Markdown 的区块引用看起来就真的像是引用一段文字,就像你曾在电子邮件中见过的那样。</p>
<h1 id="2-区块元素"><a href="#2-区块元素" class="headerlink" title="2. 区块元素"></a>2. 区块元素</h1><h2 id="2-1-段落和换行"><a href="#2-1-段落和换行" class="headerlink" title="2.1 段落和换行"></a>2.1 段落和换行</h2><p>一个 Markdown 段落是由一个或多个连续的文本行组成,它的前后要有一个以上的空行(空行的定义是显示上看起来像是空的,便会被视为空行。比方说,若某一行只包含空格和制表符,则该行也会被视为空行)。普通段落不该用空格或制表符来缩进。</p>
<p>「由一个或多个连续的文本行组成」这句话其实暗示了 Markdown 允许段落内的强迫换行(插入换行符),这个特性和其他大部分的 text-to-HTML 格式不一样(包括 Movable Type 的「Convert Line Breaks」选项),其它的格式会把每个换行符都转成 <code><br /></code> 标签。</p>
<p>如果你确实想要依赖 Markdown 来插入 <code><br /></code> 标签的话,在插入处先按入两个以上的空格然后回车。</p>
<p>的确,需要多费点事(多加空格)来产生 <code><br /></code> ,但是简单地「每个换行都转换为 <code><br /></code>的方法在 Markdown 中并不适合, Markdown 中 email 式的 区块引用 和多段落的 列表 在使用换行来排版的时候,不但更好用,还更方便阅读。</p>
<h2 id="2-2-标题"><a href="#2-2-标题" class="headerlink" title="2.2 标题"></a>2.2 标题</h2><p>Markdown 支持两种标题的语法,类 Setext 和类 atx 形式。</p>
<p>类 Setext 形式是用底线的形式,利用 <code>=</code> (最高阶标题)和 <code>-</code> (第二阶标题),例如:</p>
<pre><code>This is an H1
=============
This is an H2
-------------
</code></pre><p>类 Atx 形式则是在行首插入 1 到 6 个 # ,对应到标题 1 到 6 阶,例如:</p>
<pre><code># 这是 H1
## 这是 H2
###### 这是 H6
</code></pre><h2 id="2-3-区块引用-Blockquotes"><a href="#2-3-区块引用-Blockquotes" class="headerlink" title="2.3 区块引用 Blockquotes"></a>2.3 区块引用 Blockquotes</h2><p>Markdown 标记区块引用是使用类似 email 中用 > 的引用方式。如果你还熟悉在 email 信件中的引言部分,你就知道怎么在 Markdown 文件中建立一个区块引用,那会看起来像是你自己先断好行,然后在每行的最前面加上 <code>></code> :</p>
<blockquote>
<p>This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,<br>consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.<br>Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.</p>
<p>Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse<br>id sem consectetuer libero luctus adipiscing. </p>
</blockquote>
<p>code:</p>
<pre><code>> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
> consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
> Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
>
> Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
> id sem consectetuer libero luctus adipiscing.
</code></pre><p>Markdown 也允许你偷懒只在整个段落的第一行最前面加上 <code>></code>:<br>区块引用可以嵌套(例如:引用内的引用),只要根据层次加上不同数量的 <code>></code> :</p>
<blockquote>
<p>This is the first level of quoting.</p>
<blockquote>
<p>This is nested blockquote.</p>
</blockquote>
<p>Back to the first level.</p>
</blockquote>
<p>code:</p>
<pre><code>> This is the first level of quoting.
>
> > This is nested blockquote.
>
> Back to the first level.
</code></pre><p>引用的区块内也可以使用其他的 Markdown 语法,包括标题、列表、代码区块等:</p>
<blockquote>
<h2 id="这是一个标题。"><a href="#这是一个标题。" class="headerlink" title="这是一个标题。"></a>这是一个标题。</h2><ol>
<li>这是第一行列表项。</li>
<li>这是第二行列表项。</li>
</ol>
<p>给出一些例子代码:</p>
<pre><code>return shell_exec("echo $input | $markdown_script");
</code></pre></blockquote>
<p>code:</p>
<pre><code>> ## 这是一个标题。
>
> 1. 这是第一行列表项。
> 2. 这是第二行列表项。
>
> 给出一些例子代码:
>
> return shell_exec("echo $input | $markdown_script");
</code></pre><h2 id="2-4-列表"><a href="#2-4-列表" class="headerlink" title="2.4 列表"></a>2.4 列表</h2><p>无序列表使用星号、加号或是减号作为列表标记。但是要注意在( * , +, and - )和文字之间需要添加空格。 </p>
<ul>
<li>Red</li>
<li>Green</li>
<li><p>Blue</p>
<pre><code>* Red
* Green
* Blue
</code></pre></li>
</ul>
<p>有序列表则使用数字接着一个英文句点:</p>
<ol>
<li>Bird</li>
<li>McHale</li>
<li><p>Parish</p>
<pre><code>1. Bird
2. McHale
3. Parish
</code></pre></li>
</ol>
<h2 id="2-5-代码区块"><a href="#2-5-代码区块" class="headerlink" title="2.5 代码区块"></a>2.5 代码区块</h2><p>和程序相关的写作或是标签语言原始码通常会有已经排版好的代码区块,通常这些区块我们并不希望它以一般段落文件的方式去排版,而是照原来的样子显示,Markdown 会用 <code><pre></code> 和 <code><code></code> 标签来把代码区块包起来。</p>
<p>要在 Markdown 中建立代码区块很简单,只要简单地缩进 4 个空格或是 1 个制表符就可以,例如,下面的输入:</p>
<pre><code>这是一个普通段落:
这是一个代码区块。
</code></pre><p>一个代码区块会一直持续到没有缩进的那一行(或是文件结尾)。</p>
<h2 id="2-6-分隔线"><a href="#2-6-分隔线" class="headerlink" title="2.6 分隔线"></a>2.6 分隔线</h2><p>你可以在一行中用三个以上的星号、减号、底线来建立一个分隔线,行内不能有其他东西。你也可以在星号或是减号中间插入空格。下面每种写法都可以建立分隔线:</p>
<pre><code>* * *
***
*****
- - -
---------------------------------------
</code></pre><h1 id="3-区段元素"><a href="#3-区段元素" class="headerlink" title="3 区段元素"></a>3 区段元素</h1><h2 id="3-1-链接"><a href="#3-1-链接" class="headerlink" title="3.1 链接"></a>3.1 链接</h2><p>Markdown 支持两种形式的链接语法: 行内式和参考式两种形式。</p>
<p>不管是哪一种,链接文字都是用 [方括号] 来标记。</p>
<p>要建立一个行内式的链接,只要在方块括号后面紧接着圆括号并插入网址链接即可,如果你还想要加上链接的 title 文字,只要在网址后面,用双引号把 title 文字包起来即可,例如:</p>
<p>This is <a href="http://example.com/" title="Title" target="_blank" rel="external">an example</a> inline link.<br><a href="http://example.net/" target="_blank" rel="external">This link</a> has no title attribute.</p>
<pre><code>This is [an example](http://example.com/ "Title") inline link.
[This link](http://example.net/) has no title attribute.
</code></pre><p>链接内容定义的形式为:</p>
<ul>
<li>方括号(前面可以选择性地加上至多三个空格来缩进),里面输入链接文字</li>
<li>接着一个冒号</li>
<li>接着一个以上的空格或制表符</li>
<li>接着链接的网址</li>
<li>选择性地接着 title 内容,可以用单引号、双引号或是括弧包着 </li>
</ul>
<p>链接的定义可以放在文件中的任何一个地方,我比较偏好直接放在链接出现段落的后面,你也可以把它放在文件最后面,就像是注解一样。<br>下面是一个参考式链接的范例:</p>
<p>I get 10 times more traffic from <a href="http://google.com/" title="Google" target="_blank" rel="external">Google</a> than from<br><a href="http://search.yahoo.com/" title="Yahoo Search" target="_blank" rel="external">Yahoo</a> or <a href="http://search.msn.com/" title="MSN Search" target="_blank" rel="external">MSN</a>.</p>
<pre><code>I get 10 times more traffic from [Google] [1] than from
[Yahoo] [2] or [MSN] [3].
[1]: http://google.com/ "Google"
[2]: http://search.yahoo.com/ "Yahoo Search"
[3]: http://search.msn.com/ "MSN Search"
</code></pre><h2 id="3-2-强调"><a href="#3-2-强调" class="headerlink" title="3.2 强调"></a>3.2 强调</h2><p>Markdown 使用星号(<code>*</code>)和底线(<code>_</code>)作为标记强调字词的符号,被 <code>*</code> 或 <code>_</code> 包围的字词会被转成用 <code><em></code> 标签包围,用两个 <code>*</code> 或 <code>_</code> 包起来的话,则会被转成<code><strong></code>,例如:</p>
<p><em>single asterisks</em></p>
<p><em>single underscores</em></p>
<p><strong>double asterisks</strong></p>
<p><strong>double underscores</strong></p>
<pre><code>*single asterisks*
_single underscores_
**double asterisks**
__double underscores__
</code></pre><p>但是如果你的 * 和 _ 两边都有空白的话,它们就只会被当成普通的符号。</p>
<p>如果要在文字前后直接插入普通的星号或底线,你可以用反斜线:<br>*this text is surrounded by literal asterisks*</p>
<pre><code>\*this text is surrounded by literal asterisks\*
</code></pre><h2 id="3-3-代码"><a href="#3-3-代码" class="headerlink" title="3.3 代码"></a>3.3 代码</h2><p>如果要标记一小段行内代码,你可以用反引号把它包起来(`),例如:</p>
<p>(`不是单引号而是左上角的ESC下面~中的`)</p>
<p>Use the <code>printf()</code> function.</p>
<pre><code>Use the `printf()` function.
</code></pre><h2 id="3-4-图片"><a href="#3-4-图片" class="headerlink" title="3.4 图片"></a>3.4 图片</h2><p>很明显地,要在纯文字应用中设计一个「自然」的语法来插入图片是有一定难度的。</p>
<p>Markdown 使用一种和链接很相似的语法来标记图片,同样也允许两种样式: 行内式和参考式。</p>
<p>行内式的图片语法看起来像是:</p>
<pre><code>

</code></pre><p>详细叙述如下:</p>
<ul>
<li>一个惊叹号 !</li>
<li>接着一个方括号,里面放上图片的替代文字</li>
<li>接着一个普通括号,里面放上图片的网址,最后还可以用引号包住并加上 选择性的 ‘title’ 文字。</li>
</ul>
<p>参考式的图片语法则长得像这样:</p>
<pre><code>![Alt text][id]
</code></pre><p>「id」是图片参考的名称,图片参考的定义方式则和连结参考一样:</p>
<pre><code>[id]: url/to/image "Optional title attribute"
</code></pre><h1 id="4-其它"><a href="#4-其它" class="headerlink" title="4. 其它"></a>4. 其它</h1><h2 id="4-1-自动链接"><a href="#4-1-自动链接" class="headerlink" title="4.1 自动链接"></a>4.1 自动链接</h2><p>Markdown 支持以比较简短的自动链接形式来处理网址和电子邮件信箱,只要是用方括号包起来, Markdown 就会自动把它转成链接。一般网址的链接文字就和链接地址一样,例如:<br><a href="http://light-white.club/" target="_blank" rel="external">http://light-white.club/</a></p>
<pre><code><http://light-white.club/>
</code></pre><p>邮址的自动链接也很类似</p>
<a href="mailto:light-white@outlook.com">light-white@outlook.com</a>
<pre><code><light-white@outlook.com>
</code></pre><h2 id="4-2-反斜杠"><a href="#4-2-反斜杠" class="headerlink" title="4.2 反斜杠"></a>4.2 反斜杠</h2><p>Markdown 可以利用反斜杠来插入一些在语法中有其它意义的符号,例如:如果你想要用星号加在文字旁边的方式来做出强调效果(但不用 <code><em></code> 标签),你可以在星号的前面加上反斜杠:</p>
<p>*literal asterisks*</p>
<pre><code>\*literal asterisks\*
</code></pre><p>Markdown 支持以下这些符号前面加上反斜杠来帮助插入普通的符号:</p>
<pre><code>\ 反斜线
` 反引号
* 星号
_ 底线
{} 花括号
[] 方括号
() 括弧
# 井字号
+ 加号
- 减号
. 英文句点
! 惊叹号
</code></pre>]]></content>
<summary type="html">
<h1 id="1-Markdown概述"><a href="#1-Markdown概述" class="headerlink" title="1. Markdown概述"></a>1. Markdown概述</h1><p><strong>宗旨</strong></p>
<p>M
</summary>
<category term="Markdown" scheme="http://light-white.me/tags/Markdown/"/>
<category term="blog" scheme="http://light-white.me/tags/blog/"/>
</entry>
<entry>
<title>Hexo+Github博客搭建</title>
<link href="http://light-white.me/2016/04/27/Hexo-Github%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/"/>
<id>http://light-white.me/2016/04/27/Hexo-Github博客搭建/</id>
<published>2016-04-27T08:50:26.000Z</published>
<updated>2016-09-23T08:06:35.655Z</updated>
<content type="html"><![CDATA[<h1 id="1-Hexo介绍"><a href="#1-Hexo介绍" class="headerlink" title="1. Hexo介绍"></a>1. Hexo介绍</h1><p>Hexo 是一个简单地、轻量地、基于Node的一个静态博客框架。通过Hexo我们可以快速创建自己的博客,仅需要几条命令就可以完成。<br>发布时,Hexo可以部署在自己的Node服务器上面,也可以部署github上面。对于个人用户来说,部署在github上好处颇多,不仅可以省去服务器的成本,还可以减少各种系统运维的麻烦事(系统管理、备份、网络)。所以,基于github的个人站点,正在开始流行起来….<br>Hexo的官方网站: <a href="https://hexo.io/" target="_blank" rel="external">http://hexo.io/</a>也是基于Github构建的网站。</p>
<h1 id="2-配置环境"><a href="#2-配置环境" class="headerlink" title="2. 配置环境"></a>2. 配置环境</h1><p>安装Node(必须)<br>作用:用来生成静态页面的<br>到Node.js官网下载相应平台的最新版本,一路安装即可。<br>安装Git(必须)<br>作用:把本地的hexo内容提交到github上去.<br>安装sublime 用来编辑文件<br>在Github上new repository<br><img src="http://7xtgk5.com1.z0.glb.clouddn.com/16-4-27/1924680.jpg" alt=""></p>
<p>格式为your_user_name.github.io</p>
<h1 id="3-安装hexo"><a href="#3-安装hexo" class="headerlink" title="3.安装hexo"></a>3.安装hexo</h1><p>打开git shell 利用 npm 命令即可安装<br>npm install -g hexo<br>这里我们可以使用hexo version查看一下版本<br>我现在用的版本是3.2.0 本文也是基于Hexo3.2.0所写<br>后续变更请查看官方文档,Hexo的官方网站: <a href="https://hexo.io/" target="_blank" rel="external">http://hexo.io/</a> </p>
<h2 id="3-1创建hexo文件夹"><a href="#3-1创建hexo文件夹" class="headerlink" title="3.1创建hexo文件夹"></a>3.1创建hexo文件夹</h2><p>安装完成后,在你喜爱的文件夹下(如D:\hexo)Hexo 即会自动在目标文件夹建立网站所需要的所有文件。<br>hexo init your_user_name.github.io<br>安装好后,我们就可以使用Hexo创建项目了。<br>cd your_user_name.github.io<br>进入目录,并启动Hexo服务器。<br>Hexo server<br>这时端口4000被打开了,我们能过浏览器打开地址,<a href="http://localhost:4000/" target="_blank" rel="external">http://localhost:4000/</a> 。<br><img src="http://7xtgk5.com1.z0.glb.clouddn.com/16-4-27/28198702.jpg" alt=""><br>打开了本地预览模式 </p>
<h1 id="4-全局配置"><a href="#4-全局配置" class="headerlink" title="4.全局配置"></a>4.全局配置</h1><p>_config.yml是全局的配置文件<br>接下来我只写出我们会用到的部分</p>
<pre><code># Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/
# Site
title: Hexo#站点名,站点左上角
subtitle: #副标题,站点左上角
description: #站点描述
author: John Doe#作者 站点左下角
language:#语言 中文zh-CN
timezone:#时区
# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy: #部署配置
type: git
repo: https://github.com/your_user_name/ your_user_name.github.io.git
branch: master
</code></pre><p>我们主要需要改的是deploy部分 </p>
<h1 id="5-部署到github"><a href="#5-部署到github" class="headerlink" title="5.部署到github"></a>5.部署到github</h1><p>当我们改好配置文件之后我们就可以把hexo部署到github上了<br>在git shell中进入目录<br>我们需要手动配置一点东西<br>npm install hexo-renderer-ejs–save<br>npm install hexo-renderer-stylus–save<br>npm install hexo-renderer-marked–save<br>npm install hexo-server—save<br>然后生成静态页面<br>hexo g<br>部署到github<br>hexo d </p>
<h1 id="6-创建新文章"><a href="#6-创建新文章" class="headerlink" title="6.创建新文章"></a>6.创建新文章</h1><p>hexo new 新文章<br>在your_user_name.github.io/source/_posts下会生成 Hexo+Github博客搭建.md<br>我们使用sublime 打开文件,以markdown语法编写</p>
<pre><code>title: 新的开始
date: 2014-05-07 18:44:12
updated : 2014-05-10 18:44:12
permalink: abc
tags:
- 开始
- 我
- 日记
categories:
- 日志
- 第一天
</code></pre>]]></content>
<summary type="html">
<h1 id="1-Hexo介绍"><a href="#1-Hexo介绍" class="headerlink" title="1. Hexo介绍"></a>1. Hexo介绍</h1><p>Hexo 是一个简单地、轻量地、基于Node的一个静态博客框架。通过Hexo我们可以快速
</summary>
<category term="blog" scheme="http://light-white.me/tags/blog/"/>
<category term="Hexo" scheme="http://light-white.me/tags/Hexo/"/>
<category term="Github" scheme="http://light-white.me/tags/Github/"/>
</entry>
</feed>