-
Notifications
You must be signed in to change notification settings - Fork 0
/
rss.xml
995 lines (995 loc) · 263 KB
/
rss.xml
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
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>奈良池博客</title>
<subtitle>记录学习与生活</subtitle>
<icon>https://www.naraci.top/images/favicon.ico</icon>
<link>https://www.naraci.top</link>
<author>
<name>Naraci</name>
</author>
<description>No woman in heart, natural God in code!</description>
<language>zh-CN</language>
<pubDate>Thu, 28 Mar 2024 13:35:01 +0800</pubDate>
<lastBuildDate>Thu, 28 Mar 2024 13:35:01 +0800</lastBuildDate>
<category term="blog" />
<category term="奈良池" />
<category term="博客" />
<category term="Hexo" />
<category term="编程" />
<category term="code" />
<category term="Naraci" />
<category term="naraci" />
<category term="奈良池博客" />
<category term="编程技术" />
<item>
<guid isPermalink="true">https://www.naraci.top/post/25037.html</guid>
<title>记录一次vscode 插件商店 提取扩展插件 失败</title>
<link>https://www.naraci.top/post/25037.html</link>
<category term="idea" scheme="https://www.naraci.top/categories/idea/" />
<category term="id" scheme="https://www.naraci.top/tags/id/" />
<pubDate>Thu, 28 Mar 2024 13:35:01 +0800</pubDate>
<description><![CDATA[ <p><strong>今天打算下载个 React 的一个插件 奈何怎么整都显示 提取扩展失败,相对来说 国内应该支持插件的下载不用用魔法工具的加持呀,难道大陆给限制了?我便使用魔法工具来尝试下载,果然还是不行,有从网上看更改 dns , 难不成我的 dns 被污染了? 我便又去改 dns,还是不行,现在就开始有点着急了。。。然后卸载软件清空缓存 ,不出所料还是不行,软件没有问题那么就是 我本地环境的问题了,开始排查,更换网络连接 连我的手机热点。还是一样的错误, 实在没头绪了,打开搜索引擎,bing 前两页都看了 解决方法都是一致的改 dns,和 关掉代理,但是这两项试了还是不行,那么就更换搜索引擎试试,试试充满广告的度娘吧(实属没辙了)在一个文章内看见了</strong><br />
环境变量的字眼 <strong>开始行动,果然在环境变量里有个这个参数,具体怎么来的也不清楚先删掉</strong><br />
<img data-src="https://cdn.jsdelivr.net/gh/NAILIANGCHI/image-bed/20240328133034.png" alt="截图" /><br />
重启 vscode<br />
看见了插件有了更新字眼 没错 可以正常使用了<br />
<img data-src="https://cdn.jsdelivr.net/gh/NAILIANGCHI/image-bed/20240328133350.png" alt="截图" /><br />
真的很棒!!!</p>
]]></description>
</item>
<item>
<guid isPermalink="true">https://www.naraci.top/post/1.html</guid>
<title>Java单列模式</title>
<link>https://www.naraci.top/post/1.html</link>
<category term="Java" scheme="https://www.naraci.top/categories/Java/" />
<category term="Java" scheme="https://www.naraci.top/tags/Java/" />
<pubDate>Thu, 19 Oct 2023 00:00:00 +0800</pubDate>
<description><![CDATA[ <h1 id="java单列模式介绍"><a class="anchor" href="#java单列模式介绍">#</a> Java 单列模式介绍</h1>
<p>主要解决全局使用的类频繁的创建与销毁<br />
保证一个类仅有一个实例,并提供一个访问它的全局访问点<br />
<strong>创建一个 Singleton</strong></p>
<figure class="highlight java"><figcaption data-lang="java"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">SingleObject</span> <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="2"></td><td><pre> </pre></td></tr><tr><td data-num="3"></td><td><pre> <span class="token comment">// 创建 SingleObject 的一个对象</span></pre></td></tr><tr><td data-num="4"></td><td><pre> <span class="token keyword">private</span> <span class="token keyword">static</span> <span class="token class-name">SingleObject</span> instance <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SingleObject</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="5"></td><td><pre> </pre></td></tr><tr><td data-num="6"></td><td><pre> <span class="token comment">// 让构造函数为 private,这样该类就不会被实例化</span></pre></td></tr><tr><td data-num="7"></td><td><pre> <span class="token keyword">private</span> <span class="token class-name">SingleObject</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">&#123;</span><span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="8"></td><td><pre> </pre></td></tr><tr><td data-num="9"></td><td><pre> <span class="token comment">// 获取唯一可用的对象</span></pre></td></tr><tr><td data-num="10"></td><td><pre> <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token class-name">SingleObject</span> <span class="token function">getInstance</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="11"></td><td><pre> <span class="token keyword">return</span> instance<span class="token punctuation">;</span></pre></td></tr><tr><td data-num="12"></td><td><pre> <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="13"></td><td><pre> </pre></td></tr><tr><td data-num="14"></td><td><pre> <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">showMessage</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="15"></td><td><pre> <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"Hello World!"</span><span class="token punctuation">)</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="16"></td><td><pre> <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="17"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr></table></figure><p><strong>从 singleton 类获取唯一的对象</strong></p>
<figure class="highlight java"><figcaption data-lang="java"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">SingletonPatternDemo</span> <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="2"></td><td><pre> <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="3"></td><td><pre> </pre></td></tr><tr><td data-num="4"></td><td><pre> <span class="token comment">// 不合法的构造函数</span></pre></td></tr><tr><td data-num="5"></td><td><pre> <span class="token comment">// 编译时错误:构造函数 SingleObject () 是不可见的</span></pre></td></tr><tr><td data-num="6"></td><td><pre> <span class="token comment">//SingleObject object = new SingleObject();</span></pre></td></tr><tr><td data-num="7"></td><td><pre> </pre></td></tr><tr><td data-num="8"></td><td><pre> <span class="token comment">// 获取唯一可用的对象</span></pre></td></tr><tr><td data-num="9"></td><td><pre> <span class="token class-name">SingleObject</span> object <span class="token operator">=</span> <span class="token class-name">SingleObject</span><span class="token punctuation">.</span><span class="token function">getInstance</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="10"></td><td><pre> </pre></td></tr><tr><td data-num="11"></td><td><pre> <span class="token comment">// 显示消息</span></pre></td></tr><tr><td data-num="12"></td><td><pre> object<span class="token punctuation">.</span><span class="token function">showMessage</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="13"></td><td><pre> <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="14"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr></table></figure><p>执行输出</p>
<blockquote>
<p>Hello World!</p>
</blockquote>
<h2 id="懒汉式-线程不安全-不支持多线程"><a class="anchor" href="#懒汉式-线程不安全-不支持多线程">#</a> 懒汉式 线程不安全 (不支持多线程)</h2>
<p><strong>特点:</strong> 最基本的实现方式,但是不支持多线程,没有加锁 synchronized, 所以严格意义上它并不算单列模式</p>
<figure class="highlight java"><figcaption data-lang="java"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Singleton</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="2"></td><td><pre> <span class="token keyword">private</span> <span class="token keyword">static</span> <span class="token class-name">Singleton</span> instance<span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="3"></td><td><pre> <span class="token keyword">private</span> <span class="token class-name">Singleton</span> <span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">&#123;</span><span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="4"></td><td><pre> </pre></td></tr><tr><td data-num="5"></td><td><pre> <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token class-name">Singleton</span> <span class="token function">getInstance</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="6"></td><td><pre> <span class="token keyword">if</span> <span class="token punctuation">(</span>instance <span class="token operator">==</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="7"></td><td><pre> instance <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Singleton</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="8"></td><td><pre> <span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="9"></td><td><pre> <span class="token keyword">return</span> instance<span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="10"></td><td><pre> <span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="11"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr></table></figure><h2 id="懒汉式-线程安全"><a class="anchor" href="#懒汉式-线程安全">#</a> 懒汉式 线程安全</h2>
<p>** 描述:** 这种方式具备很好的 lazy loading,能够在多线程中很好的工作,但是,效率很低,99% 情况下不需要同步。<br />
优点:第一次调用才初始化,避免内存浪费。<br />
缺点:必须加锁 synchronized 才能保证单例,但加锁会影响效率。<br />
getInstance () 的性能对应用程序不是很关键(该方法使用不太频繁)。</p>
<figure class="highlight java"><figcaption data-lang="java"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Singleton</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="2"></td><td><pre> <span class="token keyword">private</span> <span class="token keyword">static</span> <span class="token class-name">Singleton</span> instance<span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="3"></td><td><pre> <span class="token keyword">private</span> <span class="token class-name">Singleton</span> <span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">&#123;</span><span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="4"></td><td><pre> <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">synchronized</span> <span class="token class-name">Singleton</span> <span class="token function">getInstance</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="5"></td><td><pre> <span class="token keyword">if</span> <span class="token punctuation">(</span>instance <span class="token operator">==</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="6"></td><td><pre> instance <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Singleton</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="7"></td><td><pre> <span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="8"></td><td><pre> <span class="token keyword">return</span> instance<span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="9"></td><td><pre> <span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="10"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr></table></figure><h2 id="饿汉式"><a class="anchor" href="#饿汉式">#</a> 饿汉式</h2>
<p><strong>描述</strong>:这种方式比较常用,但容易产生垃圾对象。<br />
优点:没有加锁,执行效率会提高。<br />
缺点:类加载时就初始化,浪费内存。<br />
它基于 classloader 机制避免了多线程的同步问题,不过,instance 在类装载时就实例化,虽然导致类装载的原因有很多种,在单例模式中大多数都是调用 getInstance 方法, 但是也不能确定有其他的方式(或者其他的静态方法)导致类装载,这时候初始化 instance 显然没有达到 lazy loading 的效果。</p>
<figure class="highlight java"><figcaption data-lang="java"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Singleton</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="2"></td><td><pre> <span class="token keyword">private</span> <span class="token keyword">static</span> <span class="token class-name">Singleton</span> instance <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Singleton</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="3"></td><td><pre> <span class="token keyword">private</span> <span class="token class-name">Singleton</span> <span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">&#123;</span><span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="4"></td><td><pre> <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token class-name">Singleton</span> <span class="token function">getInstance</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="5"></td><td><pre> <span class="token keyword">return</span> instance<span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="6"></td><td><pre> <span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="7"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr></table></figure><h2 id="双检锁-双重校验锁-dcl即-double-checked-locking"><a class="anchor" href="#双检锁-双重校验锁-dcl即-double-checked-locking">#</a> 双检锁 / 双重校验锁 (### DCL,即 double-checked locking)</h2>
<p><strong>描述:</strong> 这种方式采用双锁机制,安全且在多线程情况下能保持高性能。<br />
getInstance () 的性能对应用程序很关键。</p>
<figure class="highlight java"><figcaption data-lang="java"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Singleton</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="2"></td><td><pre> <span class="token keyword">private</span> <span class="token keyword">volatile</span> <span class="token keyword">static</span> <span class="token class-name">Singleton</span> singleton<span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="3"></td><td><pre> <span class="token keyword">private</span> <span class="token class-name">Singleton</span> <span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">&#123;</span><span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="4"></td><td><pre> <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token class-name">Singleton</span> <span class="token function">getSingleton</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="5"></td><td><pre> <span class="token keyword">if</span> <span class="token punctuation">(</span>singleton <span class="token operator">==</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="6"></td><td><pre> <span class="token keyword">synchronized</span> <span class="token punctuation">(</span><span class="token class-name">Singleton</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="7"></td><td><pre> <span class="token keyword">if</span> <span class="token punctuation">(</span>singleton <span class="token operator">==</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="8"></td><td><pre> singleton <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Singleton</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="9"></td><td><pre> <span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="10"></td><td><pre> <span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="11"></td><td><pre> <span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="12"></td><td><pre> <span class="token keyword">return</span> singleton<span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="13"></td><td><pre> <span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="14"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr></table></figure><h2 id="枚举"><a class="anchor" href="#枚举">#</a> 枚举</h2>
<p><strong>描述:</strong> 这种实现方式还没有被广泛采用,但这是实现单例模式的最佳方法。它更简洁,自动支持序列化机制,绝对防止多次实例化。<br />
这种方式是 Effective Java 作者 Josh Bloch 提倡的方式,它不仅能避免多线程同步问题,而且还自动支持序列化机制,防止反序列化重新创建新的对象,绝对防止多次实例化。不过,由于 JDK1.5 之后才加入 enum 特性,用这种方式写不免让人感觉生疏,在实际工作中,也很少用。<br />
不能通过 reflection attack 来调用私有构造方法。</p>
<figure class="highlight java"><figcaption data-lang="java"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token keyword">public</span> <span class="token keyword">enum</span> <span class="token class-name">Singleton</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="2"></td><td><pre> INSTANCE<span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="3"></td><td><pre> <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">whateverMethod</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="4"></td><td><pre> <span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="5"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr></table></figure><h2 id="登记式静态内部类"><a class="anchor" href="#登记式静态内部类">#</a> 登记式 / 静态内部类</h2>
<p><strong>描述:</strong> 这种方式能达到双检锁方式一样的功效,但实现更简单。对静态域使用延迟初始化,应使用这种方式而不是双检锁方式。这种方式只适用于静态域的情况,双检锁方式可在实例域需要延迟初始化时使用。<br />
这种方式同样利用了 classloader 机制来保证初始化 instance 时只有一个线程,它跟第 3 种方式不同的是:第 3 种方式只要 Singleton 类被装载了,那么 instance 就会被实例化(没有达到 lazy loading 效果),而这种方式是 Singleton 类被装载了,instance 不一定被初始化。因为 SingletonHolder 类没有被主动使用,只有通过显式调用 getInstance 方法时,才会显式装载 SingletonHolder 类,从而实例化 instance。想象一下,如果实例化 instance 很消耗资源,所以想让它延迟加载,另外一方面,又不希望在 Singleton 类加载时就实例化,因为不能确保 Singleton 类还可能在其他的地方被主动使用从而被加载,那么这个时候实例化 instance 显然是不合适的。这个时候,这种方式相比第 3 种方式就显得很合理。</p>
<figure class="highlight java"><figcaption data-lang="java"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Singleton</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="2"></td><td><pre> <span class="token keyword">private</span> <span class="token keyword">static</span> <span class="token keyword">class</span> <span class="token class-name">SingletonHolder</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="3"></td><td><pre> <span class="token keyword">private</span> <span class="token keyword">static</span> <span class="token keyword">final</span> <span class="token class-name">Singleton</span> INSTANCE <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Singleton</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="4"></td><td><pre> <span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="5"></td><td><pre> <span class="token keyword">private</span> <span class="token class-name">Singleton</span> <span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">&#123;</span><span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="6"></td><td><pre> <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">final</span> <span class="token class-name">Singleton</span> <span class="token function">getInstance</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="7"></td><td><pre> <span class="token keyword">return</span> <span class="token class-name">SingletonHolder</span><span class="token punctuation">.</span>INSTANCE<span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="8"></td><td><pre> <span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="9"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr></table></figure> ]]></description>
</item>
<item>
<guid isPermalink="true">https://www.naraci.top/post/47333.html</guid>
<title>Java开发遇见的陌生含义</title>
<link>https://www.naraci.top/post/47333.html</link>
<category term="Java" scheme="https://www.naraci.top/categories/Java/" />
<category term="Java" scheme="https://www.naraci.top/tags/Java/" />
<pubDate>Fri, 21 Jul 2023 13:10:46 +0800</pubDate>
<description><![CDATA[ <h1 id="pom是什么"><a class="anchor" href="#pom是什么">#</a> pom 是什么?</h1>
<pre><code>pom是指`Project object Model`项目对象模型,用于描述项目配置信息。它可以自动化管理项目的依赖,编译,测试,打包等任务。它位于项目根目录。
</code></pre>
<h3 id="pomxml文件具有以下主要用途"><a class="anchor" href="#pomxml文件具有以下主要用途">#</a> pom.xml 文件具有以下主要用途:</h3>
<ol>
<li>
<p>定义项目信息:在 pom.xml 中,你可以定义项目的名称、版本号、描述等基本信息。</p>
</li>
<li>
<p>管理项目依赖:你可以在 pom.xml 中声明项目所依赖的第三方库或其他模块,Maven 将自动下载并管理这些依赖。</p>
</li>
<li>
<p>配置插件:Maven 通过插件来执行各种任务,如编译、测试、打包等。pom.xml 中可以配置这些插件的设置。</p>
</li>
<li>
<p>设置构建规则:你可以在 pom.xml 中定义项目的构建规则,例如编译时需要执行哪些操作,如何打包项目等。</p>
</li>
</ol>
<h3 id="对于新手来说以下是一些建议"><a class="anchor" href="#对于新手来说以下是一些建议">#</a> 对于新手来说,以下是一些建议:</h3>
<ol>
<li>
<p>了解基本结构:学习 pom.xml 文件的基本结构和标签含义,这对于理解和配置 Maven 项目至关重要。</p>
</li>
<li>
<p>注意依赖管理:合理管理项目的依赖非常重要。确保依赖项的版本与你的项目兼容,并尽量避免使用过多的不必要依赖。</p>
</li>
<li>
<p>阅读文档:Maven 有丰富的文档和社区资源。在遇到问题时,优先查阅相关文档和搜索解决方案,这将帮助你更快地解决问题。</p>
</li>
<li>
<p>使用版本控制:将 pom.xml 纳入版本控制系统(如 Git),确保在团队协作时项目配置的一致性。</p>
</li>
<li>
<p>注意继承和聚合:Maven 支持项目继承和聚合特性。理解这些特性的作用和用法,可以让你更好地组织复杂的项目结构。</p>
</li>
<li>
<p>小步调试:当对项目配置进行重大更改时,建议先进行小步调试,逐步验证每个更改,避免一次性引入多个问题。</p>
</li>
<li>
<p>注意 Maven 生命周期:了解 Maven 的构建生命周期和各个阶段的执行顺序,这有助于理解构建过程和插件执行顺序。</p>
</li>
</ol>
<h3 id="常用的标签"><a class="anchor" href="#常用的标签">#</a> 常用的标签</h3>
<ol>
<li>
<p><code>&lt;project&gt;</code> :定义整个项目的根标签,所有其他标签都嵌套在这个标签内。</p>
</li>
<li>
<p><code>&lt;modelVersion&gt;</code> :指定 POM 模型的版本,通常为 &quot;4.0.0&quot;。</p>
</li>
<li>
<p><code>&lt;groupId&gt;</code> :定义项目所属的组织或团队的唯一标识符。</p>
</li>
<li>
<p><code>&lt;artifactId&gt;</code> :定义项目的唯一标识符,通常用于构建生成的文件名。</p>
</li>
<li>
<p><code>&lt;version&gt;</code> :定义项目的版本号。</p>
</li>
<li>
<p><code>&lt;packaging&gt;</code> :定义项目的打包类型,如 &quot;jar&quot;、&quot;war&quot;、&quot;pom&quot; 等。</p>
</li>
<li>
<p><code>&lt;name&gt;</code> :定义项目的名称。</p>
</li>
<li>
<p><code>&lt;description&gt;</code> :定义项目的描述信息。</p>
</li>
<li>
<p><code>&lt;dependencies&gt;</code> :用于列出项目所依赖的其他库或模块。</p>
</li>
<li>
<p><code>&lt;dependency&gt;</code> :定义单个依赖项,包含 <code>&lt;groupId&gt;</code> 、 <code>&lt;artifactId&gt;</code> 和 <code>&lt;version&gt;</code> 等子标签。</p>
</li>
<li>
<p><code>&lt;properties&gt;</code> :定义项目中使用到的属性,可用于简化版本号、路径等的重复定义。</p>
</li>
<li>
<p><code>&lt;build&gt;</code> :定义项目的构建配置。</p>
</li>
<li>
<p><code>&lt;plugins&gt;</code> :用于列出项目中使用的插件配置。</p>
</li>
<li>
<p><code>&lt;plugin&gt;</code> :定义单个插件,包含 <code>&lt;groupId&gt;</code> 、 <code>&lt;artifactId&gt;</code> 和 <code>&lt;version&gt;</code> 等子标签。</p>
</li>
<li>
<p><code>&lt;repositories&gt;</code> :用于配置项目的依赖仓库。</p>
</li>
<li>
<p><code>&lt;repository&gt;</code> :定义单个依赖仓库,包含 URL 等信息。</p>
</li>
<li>
<p><code>&lt;dependencyManagement&gt;</code> :用于集中管理项目的依赖版本,让子项目继承统一的版本号。</p>
</li>
<li>
<p><code>&lt;parent&gt;</code> :用于定义当前项目的父项目,继承父项目的配置信息。</p>
</li>
</ol>
]]></description>
</item>
<item>
<guid isPermalink="true">https://www.naraci.top/post/9872.html</guid>
<title>Git指令总结</title>
<link>https://www.naraci.top/post/9872.html</link>
<category term="Git" scheme="https://www.naraci.top/categories/Git/" />
<category term="Git" scheme="https://www.naraci.top/tags/Git/" />
<pubDate>Wed, 19 Jul 2023 22:47:02 +0800</pubDate>
<description><![CDATA[ <h2 id="命令"><a class="anchor" href="#命令">#</a> 命令</h2>
<table>
<thead>
<tr>
<th>示意</th>
<th>git 命令</th>
</tr>
</thead>
<tbody>
<tr>
<td>使用 git 对文件初始化</td>
<td><code>git init</code></td>
</tr>
</tbody>
<tbody>
<tr>
<td>告诉 git ,你要对哪些文件进行存档操作,将对应的文件添加到对应的暂存区</td>
<td><code>git add &lt;file&gt;</code> , 示例: <code>git add test.txt</code></td>
</tr>
</tbody>
<tbody>
<tr>
<td>添加的暂存区之后让 master 管理员,帮我们做个存档,生成一个存档记录</td>
<td><code>git commit -m &lt;message&gt;</code> ,示例 <code>git commit -m </code> 实现了网站登录功能</td>
</tr>
</tbody>
<tbody>
<tr>
<td>有多个存档记录的时候,在各个记录存档之间切换</td>
<td><code>git reset —hard commit_id</code> ,commit_id 是对应的存档记录</td>
</tr>
</tbody>
<tbody>
<tr>
<td>git 帮你召唤一个名叫 fixbug 的新档案管理员</td>
<td><code>git checkout -b &lt;name&gt;</code> 或者 <code>git switch -c &lt;name&gt;</code> ,示例: <code>git checkout -b fixbug</code> 「创建 + 切换分支」</td>
</tr>
</tbody>
<tbody>
<tr>
<td>切换到新的分支 fixbug</td>
<td><code>git checkout &lt;name&gt;</code> 或者 <code>git switch &lt;name&gt;</code> ,示例: <code>git checkout fixbug</code></td>
</tr>
</tbody>
<tbody>
<tr>
<td>切换回 master 分支,然后把 develop 分支合并起来</td>
<td><code>git checkout master``git merge develop</code></td>
</tr>
</tbody>
<tbody>
<tr>
<td>在 develop 分支开发新功能,发现我的网站上有个 bug,切换到 master 分支,然后在 master 分支新建一个 bugfix 的分支</td>
<td><code>git checkout master``git checkout -b bugfix</code></td>
</tr>
</tbody>
<tbody>
<tr>
<td>修复完 bug,切换回 master 分支,再把 bugfix 分支合并过来</td>
<td><code>git checkout master</code></td>
</tr>
<tr>
<td><code>git merge bugfix</code></td>
</tr>
</tbody>
</table>
<h3 id="常用的git命令"><a class="anchor" href="#常用的git命令">#</a> 常用的 git 命令</h3>
<ul>
<li><code>git clone &lt;[email protected]&gt;:xxxx</code> ,下载仓库</li>
<li><code>git init</code> ,初始化本地仓库 .git</li>
<li><code>git status -sb</code> ,显示当前所有文件的状态</li>
<li><code>git add 文件路径</code> ,用来将变动加到暂存区</li>
<li><code>git commit -m &quot;信息&quot;</code> ,用来正式提交变动,提交至 .git 仓库</li>
<li>如果有新的变动,我们只需要依次执行 git add xxx 和 git commit -m 'xxx' 两个命令即可。先 add 再 commit,行了,你学会 git 了。</li>
<li><code>git log</code> 查看变更历史</li>
<li><code>git pull</code> 取回远程主机某个分支的更新,再与本地的指定分支合并</li>
<li>查看分支: <code>git branch</code></li>
<li>创建分支: <code>git branch &lt;name&gt;</code></li>
<li>切换分支: <code>git checkout &lt;name&gt;</code> 或者 <code>git switch &lt;name&gt;</code></li>
<li>创建 + 切换分支: <code>git checkout -b &lt;name&gt;</code> 或者 <code>git switch -c &lt;name&gt;</code></li>
<li>合并某分支到当前分支: <code>git merge &lt;name&gt;</code></li>
<li>删除分支: <code>git branch -d &lt;name&gt;</code></li>
</ul>
<p>-- 其余待补充 --</p>
]]></description>
</item>
<item>
<guid isPermalink="true">https://www.naraci.top/post/61264.html</guid>
<title>PHP面向对象梳理笔记</title>
<link>https://www.naraci.top/post/61264.html</link>
<category term="PHP" scheme="https://www.naraci.top/categories/PHP/" />
<category term="PHP" scheme="https://www.naraci.top/tags/PHP/" />
<pubDate>Thu, 13 Apr 2023 16:29:14 +0800</pubDate>
<description><![CDATA[ <h1 id="前言"><a class="anchor" href="#前言">#</a> 前言</h1>
<p>专业课本上写的面向对象实例没有清晰明了的概括出来,代码参杂混乱让人实在是摸不出头脑这时候就该面向浏览器的编程学习了。</p>
<h2 id="对象的三个特性"><a class="anchor" href="#对象的三个特性">#</a> 对象的三个特性:</h2>
<p><strong>摘自:</strong> <code>[什么是PHP面向对象 - php完全自学手册 - php中文网手册]</code> (<span class="exturl" data-url="aHR0cHM6Ly93d3cucGhwLmNuL3BocC9waHAtb29wLmh0bWw=">https://www.php.cn/php/php-oop.html</span>)</p>
<ul>
<li>对象的行为:如拿过来,放下等就是行为。</li>
<li>对象的形态:如颜色,尺寸,外型。</li>
<li>对象的表示:对象的表示相当于身份证,具体区分在相同的行为于状态下有什么不同。</li>
</ul>
<h3 id="面向对象的内容"><a class="anchor" href="#面向对象的内容">#</a> 面向对象的内容</h3>
<ul>
<li>类 :定义了一件事物的抽象特点。类的定义包含了数据的形式以及对数据的操作。</li>
<li>对象:是类的实例 ( <code>根据关键字new可以实例化对象</code> )</li>
<li>成员变量 : 定义在类的内部的变量。该变量的值是对外不可见的,但是可以通过成员函数访问,在类被实例化对象后该变量可称为对象的属性、</li>
<li>成员函数 : 定义在类的内部,可以用于访问对象的数据。</li>
<li>继承 : 继承性是子类自动共享父类数据结构的方法和机制,这是类之间的一种关系。在定义和实现一个类的时候,可以在一个已经存在的类的基础之上类进行,把这个已经存在的类所定义的内容作为自己的内容,并加入若干新的内容、</li>
<li>父类 : 一个类被其他类继承,可以将该类称之为父类或者基类,或超类。</li>
<li>子类 : 一个继承其他类为子类,也可称之为派生类。</li>
<li>多态 : 多态性是指相同的操作或函数,过程可作用多种类型的对象并获得不同的效果。不同的对象,收到同一消息可以产生不同的结果,这种现象称为多态性。</li>
<li>重载 : 简单说,就是函数或者方法有同样的名称,但是参数列表不相同的情形,这样的同名不同参数的函数或者方法之间,互相称之为重载函数或者方法。</li>
<li>抽象性 : 抽象性是指将具有一致的数据结构(属性)和行为(操作)的对象抽象成类。一个类就是这样一种抽象,它反映了与应用有关的重要性质,而忽略其他一些无关内容。任何类的划分都是主观的,但必须与具体的应用有关。</li>
<li>封装 : 封装是指将现实世界中存在的某个客体的属性与行为绑定在一起,并放置在一个逻辑单元内。</li>
<li>构造函数 : 主要用来在创建对象时初始化对象, 即为对象成员变量赋初始值,总与 new 运算符一起使用在创建对象的语句中。</li>
<li>析构函数 : 析构函数 (destructor) 与构造函数相反,当对象结束其生命周期时(例如对象所在的函数已调用完毕),系统自动执行析构函数。析构函数往往用来做 &quot;清理善后&quot; 的工作(例如在建立对象时用 new 开辟了一片内存空间,应在退出前在析构函数中用 delete 释放)。</li>
</ul>
<h3 id="语法"><a class="anchor" href="#语法">#</a> 语法</h3>
<h4 id="创建定义一个类"><a class="anchor" href="#创建定义一个类">#</a> 创建定义一个类</h4>
<figure class="highlight php"><figcaption data-lang="PHP"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token php language-php"><span class="token delimiter important">&lt;?php</span></pre></td></tr><tr><td data-num="2"></td><td><pre><span class="token keyword">class</span> <span class="token class-name-definition class-name">car</span> <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="3"></td><td><pre><span class="token comment">/* 成员变量 */</span></pre></td></tr><tr><td data-num="4"></td><td><pre><span class="token keyword">var</span> color<span class="token punctuation">;</span></pre></td></tr><tr><td data-num="5"></td><td><pre><span class="token keyword">var</span> carname<span class="token punctuation">;</span></pre></td></tr><tr><td data-num="6"></td><td><pre><span class="token comment">/* 成员函数 */</span></pre></td></tr><tr><td data-num="7"></td><td><pre><span class="token keyword">function</span> <span class="token function-definition function">setColor</span><span class="token punctuation">(</span><span class="token variable">$par</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="8"></td><td><pre> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">color</span> <span class="token operator">=</span> <span class="token variable">$par</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="9"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="10"></td><td><pre><span class="token keyword">function</span> <span class="token function-definition function">getColor</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="11"></td><td><pre> <span class="token keyword">echo</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">color</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="12"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="13"></td><td><pre><span class="token keyword">function</span> <span class="token function-definition function">setCarname</span><span class="token punctuation">(</span><span class="token variable">$par</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="14"></td><td><pre> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">carname</span> <span class="token operator">=</span> <span class="token variable">$par</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="15"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="16"></td><td><pre><span class="token keyword">function</span> <span class="token function-definition function">getCarname</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="17"></td><td><pre> <span class="token keyword">echo</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">carname</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="18"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="19"></td><td><pre><span class="token punctuation">&#125;</span></span></pre></td></tr></table></figure><blockquote>
<p>$this 是自身的对象</p>
</blockquote>
<p>传参和访问对象里</p>
<figure class="highlight php"><figcaption data-lang="PHP"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token variable">$car</span> <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">car</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="2"></td><td><pre><span class="token variable">$car</span><span class="token operator">-></span><span class="token function">setCarname</span><span class="token punctuation">(</span><span class="token string double-quoted-string">"bwm"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="3"></td><td><pre><span class="token variable">$car</span><span class="token operator">-></span><span class="token function">setColor</span><span class="token punctuation">(</span><span class="token string double-quoted-string">"red"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="4"></td><td><pre> </pre></td></tr><tr><td data-num="5"></td><td><pre><span class="token variable">$car</span><span class="token operator">-></span><span class="token function">getColor</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="6"></td><td><pre><span class="token variable">$car</span><span class="token operator">-></span><span class="token function">getCarname</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></pre></td></tr></table></figure><h4 id="构造函数"><a class="anchor" href="#构造函数">#</a> 构造函数</h4>
<p>构造函数 ,是一种特殊的方法。主要用来在创建对象时初始化对象, 即为对象成员变量赋初始值,总与 new 运算符一起使用在创建对象的语句中。</p>
<figure class="highlight php"><figcaption data-lang="PHP"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token keyword">class</span> <span class="token class-name-definition class-name">people</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="2"></td><td><pre><span class="token comment">// 成员变量 </span></pre></td></tr><tr><td data-num="3"></td><td><pre> <span class="token keyword">var</span> <span class="token variable">$name</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="4"></td><td><pre> <span class="token keyword">var</span> <span class="token variable">$age</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="5"></td><td><pre> <span class="token keyword">function</span> <span class="token function-definition function">__construct</span><span class="token punctuation">(</span><span class="token variable">$Name</span><span class="token punctuation">,</span><span class="token variable">$Age</span><span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="6"></td><td><pre> <span class="token punctuation">&#123;</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">name</span> <span class="token operator">=</span> <span class="token variable">$Name</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="7"></td><td><pre> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">age</span> <span class="token operator">=</span> <span class="token variable">$Age</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="8"></td><td><pre> <span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="9"></td><td><pre><span class="token comment">// 成员函数 </span></pre></td></tr><tr><td data-num="10"></td><td><pre> <span class="token keyword">function</span> <span class="token function-definition function">setName</span><span class="token punctuation">(</span><span class="token variable">$par</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="11"></td><td><pre> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">name</span> <span class="token operator">=</span> <span class="token variable">$par</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="12"></td><td><pre> <span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="13"></td><td><pre> <span class="token keyword">function</span> <span class="token function-definition function">getName</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="14"></td><td><pre> <span class="token keyword">echo</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">name</span><span class="token operator">.</span><span class="token constant">PHP_EOL</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="15"></td><td><pre> <span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="16"></td><td><pre> <span class="token keyword">function</span> <span class="token function-definition function">setAge</span><span class="token punctuation">(</span><span class="token variable">$par</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="17"></td><td><pre> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">age</span> <span class="token operator">=</span> <span class="token variable">$par</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="18"></td><td><pre> <span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="19"></td><td><pre> <span class="token keyword">function</span> <span class="token function-definition function">getAge</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="20"></td><td><pre> <span class="token keyword">echo</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">age</span><span class="token operator">.</span><span class="token constant">PHP_EOL</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="21"></td><td><pre> <span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="22"></td><td><pre><span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="23"></td><td><pre><span class="token comment">// 实例化对象 </span></pre></td></tr><tr><td data-num="24"></td><td><pre><span class="token variable">$pep</span> <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">people</span><span class="token punctuation">(</span><span class="token string double-quoted-string">"zhaoyu"</span><span class="token punctuation">,</span><span class="token string double-quoted-string">"21"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="25"></td><td><pre> </pre></td></tr><tr><td data-num="26"></td><td><pre><span class="token comment">// 调用成员函数 </span></pre></td></tr><tr><td data-num="27"></td><td><pre><span class="token variable">$pep</span><span class="token operator">-></span><span class="token function">getName</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="28"></td><td><pre><span class="token variable">$pep</span><span class="token operator">-></span><span class="token function">getAge</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></pre></td></tr></table></figure><blockquote>
<p><strong>可以看出构造函数和上面普通函数不同的是直接就可以在 new 方法里直接传参省去 set 方法</strong></p>
</blockquote>
<h4 id="析构函数"><a class="anchor" href="#析构函数">#</a> 析构函数</h4>
<p>析构函数 (destructor) 与构造函数相反,当对象结束其生命周期时(例如对象所在的函数已调用完毕),系统自动执行析构函数。</p>
<figure class="highlight php"><figcaption data-lang="PHP"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token comment">/* 析构函数语法 </pre></td></tr><tr><td data-num="2"></td><td><pre>viod_destruct (void);*/</span> </pre></td></tr><tr><td data-num="3"></td><td><pre> </pre></td></tr><tr><td data-num="4"></td><td><pre><span class="token keyword">class</span> <span class="token class-name-definition class-name">Xigouhanshu</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="5"></td><td><pre> <span class="token keyword">function</span> <span class="token function-definition function">__construct</span><span class="token punctuation">(</span><span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="6"></td><td><pre> <span class="token punctuation">&#123;</span> <span class="token keyword">print</span> <span class="token string double-quoted-string">"构造函数\n"</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="7"></td><td><pre> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">name</span> <span class="token operator">=</span> <span class="token string double-quoted-string">"Xigouhanshu"</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="8"></td><td><pre> <span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="9"></td><td><pre> <span class="token keyword">function</span> <span class="token function-definition function">__destruct</span><span class="token punctuation">(</span><span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="10"></td><td><pre> <span class="token punctuation">&#123;</span> <span class="token comment">// TODO: Implement __destruct() method. </span></pre></td></tr><tr><td data-num="11"></td><td><pre> <span class="token keyword">print</span> <span class="token string double-quoted-string">"销毁"</span><span class="token operator">.</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">name</span> <span class="token operator">.</span> <span class="token string double-quoted-string">"\n"</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="12"></td><td><pre> <span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="13"></td><td><pre><span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="14"></td><td><pre> </pre></td></tr><tr><td data-num="15"></td><td><pre><span class="token variable">$object</span> <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Xigouhanshu</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></pre></td></tr></table></figure><h4 id="继承"><a class="anchor" href="#继承">#</a> 继承</h4>
<p>PHP 使用关键字 extends 来继承一个类 (父类),PHP 不支持多继承,格式如下:</p>
<figure class="highlight php"><figcaption data-lang="PHP"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token comment">/* 代码格式: </pre></td></tr><tr><td data-num="2"></td><td><pre>class child extends parent &#123; </pre></td></tr><tr><td data-num="3"></td><td><pre> </pre></td></tr><tr><td data-num="4"></td><td><pre>&#125;*/</span> </pre></td></tr><tr><td data-num="5"></td><td><pre><span class="token comment">// 引入父类文件 </span></pre></td></tr><tr><td data-num="6"></td><td><pre><span class="token keyword">include</span> <span class="token string double-quoted-string">"../类与对象/main.php"</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="7"></td><td><pre> </pre></td></tr><tr><td data-num="8"></td><td><pre><span class="token keyword">class</span> <span class="token class-name-definition class-name">child</span> <span class="token keyword">extends</span> <span class="token class-name">car</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="9"></td><td><pre> <span class="token keyword">var</span> <span class="token variable">$category</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="10"></td><td><pre> <span class="token keyword">function</span> <span class="token function-definition function">setCate</span><span class="token punctuation">(</span><span class="token variable">$par</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="11"></td><td><pre> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">category</span> <span class="token operator">=</span> <span class="token variable">$par</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="12"></td><td><pre> <span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="13"></td><td><pre> </pre></td></tr><tr><td data-num="14"></td><td><pre> <span class="token keyword">function</span> <span class="token function-definition function">getCate</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="15"></td><td><pre> <span class="token keyword">echo</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">category</span> <span class="token operator">.</span> <span class="token constant">PHP_EOL</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="16"></td><td><pre> <span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="17"></td><td><pre><span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="18"></td><td><pre><span class="token variable">$test</span> <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">child</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="19"></td><td><pre><span class="token variable">$test</span><span class="token operator">-></span><span class="token function">setColor</span><span class="token punctuation">(</span><span class="token string double-quoted-string">"yellow"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="20"></td><td><pre><span class="token variable">$test</span><span class="token operator">-></span><span class="token function">getColor</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="21"></td><td><pre><span class="token variable">$test</span><span class="token operator">-></span><span class="token function">setCate</span><span class="token punctuation">(</span><span class="token string double-quoted-string">"pen"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="22"></td><td><pre><span class="token variable">$test</span><span class="token operator">-></span><span class="token function">getCate</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></pre></td></tr></table></figure><blockquote>
<p>上面父类引用的是上面定义类的父类通过继承父类可以通过子类来调用父类的方法</p>
</blockquote>
<h4 id="方法重载"><a class="anchor" href="#方法重载">#</a> 方法重载</h4>
<p>如果从父类继承的方法不能满足子类的需求,可以对其进行改写,这个过程叫方法的覆盖(override),也称为方法的重写。</p>
<figure class="highlight php"><figcaption data-lang="PHP"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token comment">// 引入父类文件</span></pre></td></tr><tr><td data-num="2"></td><td><pre><span class="token keyword">include</span> <span class="token string double-quoted-string">"../类与对象/main.php"</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="3"></td><td><pre> </pre></td></tr><tr><td data-num="4"></td><td><pre><span class="token keyword">class</span> <span class="token class-name-definition class-name">childs</span> <span class="token keyword">extends</span> <span class="token class-name">car</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="5"></td><td><pre> <span class="token keyword">function</span> <span class="token function-definition function">getColor</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="6"></td><td><pre> <span class="token keyword">echo</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">color</span> <span class="token operator">.</span> <span class="token constant">PHP_EOL</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="7"></td><td><pre> <span class="token keyword">return</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">color</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="8"></td><td><pre> <span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="9"></td><td><pre> </pre></td></tr><tr><td data-num="10"></td><td><pre><span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="11"></td><td><pre><span class="token variable">$test</span> <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">childs</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="12"></td><td><pre><span class="token variable">$test</span><span class="token operator">-></span><span class="token function">setColor</span><span class="token punctuation">(</span><span class="token string double-quoted-string">"black"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="13"></td><td><pre><span class="token variable">$test</span><span class="token operator">-></span><span class="token function">getColor</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></pre></td></tr></table></figure><blockquote>
<p>上面可以明确看到在子类方法中改写父类方法</p>
</blockquote>
<h4 id="访问控制"><a class="anchor" href="#访问控制">#</a> 访问控制</h4>
<p>PHP 对属性或方法的访问控制,是通过在前面添加关键字 public(公有),protected(受保护)或 private(私有)来实现的。</p>
<ul>
<li>public(公有):公有的类成员可以在任何地方被访问。</li>
<li>protected(受保护):受保护的类成员则可以被其自身以及其子类和父类访问。</li>
<li>private(私有):私有的类成员则只能被其定义所在的类访问。<br />
<strong>属性访问控制</strong><br />
类属性必须定义为公有,受保护,私有之一。如果用 var 定义,则被视为公有。</li>
</ul>
<figure class="highlight php"><figcaption data-lang="PHP"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token comment">/**</pre></td></tr><tr><td data-num="2"></td><td><pre> * Define MyClass</pre></td></tr><tr><td data-num="3"></td><td><pre> */</span></pre></td></tr><tr><td data-num="4"></td><td><pre><span class="token keyword">class</span> <span class="token class-name-definition class-name">MyClass</span></pre></td></tr><tr><td data-num="5"></td><td><pre><span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="6"></td><td><pre> <span class="token keyword">public</span> <span class="token variable">$public</span> <span class="token operator">=</span> <span class="token string single-quoted-string">'Public'</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="7"></td><td><pre> <span class="token keyword">protected</span> <span class="token variable">$protected</span> <span class="token operator">=</span> <span class="token string single-quoted-string">'Protected'</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="8"></td><td><pre> <span class="token keyword">private</span> <span class="token variable">$private</span> <span class="token operator">=</span> <span class="token string single-quoted-string">'Private'</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="9"></td><td><pre> <span class="token keyword">function</span> <span class="token function-definition function">printHello</span><span class="token punctuation">(</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="10"></td><td><pre> <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="11"></td><td><pre> <span class="token keyword">echo</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">public</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="12"></td><td><pre> <span class="token keyword">echo</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">protected</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="13"></td><td><pre> <span class="token keyword">echo</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">private</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="14"></td><td><pre> <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="15"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="16"></td><td><pre><span class="token variable">$obj</span> <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">MyClass</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="17"></td><td><pre><span class="token keyword">echo</span> <span class="token variable">$obj</span><span class="token operator">-></span><span class="token property">public</span><span class="token punctuation">;</span> <span class="token comment">// 这行能被正常执行</span></pre></td></tr><tr><td data-num="18"></td><td><pre><span class="token keyword">echo</span> <span class="token variable">$obj</span><span class="token operator">-></span><span class="token property">protected</span><span class="token punctuation">;</span> <span class="token comment">// 这行会产生一个致命错误</span></pre></td></tr><tr><td data-num="19"></td><td><pre><span class="token keyword">echo</span> <span class="token variable">$obj</span><span class="token operator">-></span><span class="token property">private</span><span class="token punctuation">;</span> <span class="token comment">// 这行也会产生一个致命错误</span></pre></td></tr><tr><td data-num="20"></td><td><pre><span class="token variable">$obj</span><span class="token operator">-></span><span class="token function">printHello</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 输出 Public、Protected 和 Private</span></pre></td></tr><tr><td data-num="21"></td><td><pre><span class="token comment">/**</pre></td></tr><tr><td data-num="22"></td><td><pre> * Define MyClass2</pre></td></tr><tr><td data-num="23"></td><td><pre> */</span></pre></td></tr><tr><td data-num="24"></td><td><pre><span class="token keyword">class</span> <span class="token class-name-definition class-name">MyClass2</span> <span class="token keyword">extends</span> <span class="token class-name">MyClass</span></pre></td></tr><tr><td data-num="25"></td><td><pre><span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="26"></td><td><pre> <span class="token comment">// 可以对 public 和 protected 进行重定义,但 private 而不能</span></pre></td></tr><tr><td data-num="27"></td><td><pre> <span class="token keyword">protected</span> <span class="token variable">$protected</span> <span class="token operator">=</span> <span class="token string single-quoted-string">'Protected2'</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="28"></td><td><pre> <span class="token keyword">function</span> <span class="token function-definition function">printHello</span><span class="token punctuation">(</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="29"></td><td><pre> <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="30"></td><td><pre> <span class="token keyword">echo</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">public</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="31"></td><td><pre> <span class="token keyword">echo</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">protected</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="32"></td><td><pre> <span class="token keyword">echo</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">private</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="33"></td><td><pre> <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="34"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="35"></td><td><pre><span class="token variable">$obj2</span> <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">MyClass2</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="36"></td><td><pre><span class="token keyword">echo</span> <span class="token variable">$obj2</span><span class="token operator">-></span><span class="token property">public</span><span class="token punctuation">;</span> <span class="token comment">// 这行能被正常执行</span></pre></td></tr><tr><td data-num="37"></td><td><pre><span class="token keyword">echo</span> <span class="token variable">$obj2</span><span class="token operator">-></span><span class="token property">private</span><span class="token punctuation">;</span> <span class="token comment">// 未定义 private</span></pre></td></tr><tr><td data-num="38"></td><td><pre><span class="token keyword">echo</span> <span class="token variable">$obj2</span><span class="token operator">-></span><span class="token property">protected</span><span class="token punctuation">;</span> <span class="token comment">// 这行会产生一个致命错误</span></pre></td></tr><tr><td data-num="39"></td><td><pre><span class="token variable">$obj2</span><span class="token operator">-></span><span class="token function">printHello</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 输出 Public、Protected2 和 Undefined</span></pre></td></tr><tr><td data-num="40"></td><td><pre><span class="token delimiter important">?></span></pre></td></tr></table></figure><h4 id="接口"><a class="anchor" href="#接口">#</a> 接口</h4>
<p>使用接口(interface),可以指定某个类必须实现哪些方法,但不需要定义这些方法的具体内容。</p>
<p>接口是通过 <strong>interface</strong> 关键字来定义的,就像定义一个标准的类一样,但其中定义所有的方法都是空的。</p>
<p>接口中定义的所有方法都必须是公有,这是接口的特性。</p>
<p>要实现一个接口,使用 <strong>implements</strong> 操作符。类中必须实现接口中定义的所有方法,否则会报一个致命错误。类可以实现多个接口,用逗号来分隔多个接口的名称。</p>
<figure class="highlight php"><figcaption data-lang="PHP"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token comment">// 声明一个接口 </span></pre></td></tr><tr><td data-num="2"></td><td><pre><span class="token keyword">interface</span> <span class="token class-name-definition class-name">Bus</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="3"></td><td><pre> <span class="token keyword">function</span> <span class="token function-definition function">getByBus</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="4"></td><td><pre><span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="5"></td><td><pre> </pre></td></tr><tr><td data-num="6"></td><td><pre><span class="token keyword">class</span> <span class="token class-name-definition class-name">people</span> <span class="token keyword">implements</span> <span class="token class-name">Bus</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="7"></td><td><pre> <span class="token keyword">function</span> <span class="token function-definition function">getByBus</span><span class="token punctuation">(</span><span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="8"></td><td><pre> <span class="token punctuation">&#123;</span> <span class="token comment">// TODO: Implement getByBus() method. </span></pre></td></tr><tr><td data-num="9"></td><td><pre> <span class="token keyword">return</span> <span class="token keyword">array</span><span class="token punctuation">(</span> </pre></td></tr><tr><td data-num="10"></td><td><pre> <span class="token string double-quoted-string">"red bus"</span><span class="token punctuation">,</span> </pre></td></tr><tr><td data-num="11"></td><td><pre> <span class="token string double-quoted-string">"black bus"</span><span class="token punctuation">,</span> </pre></td></tr><tr><td data-num="12"></td><td><pre> <span class="token string double-quoted-string">"white bus"</span> </pre></td></tr><tr><td data-num="13"></td><td><pre> <span class="token punctuation">)</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="14"></td><td><pre> <span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="15"></td><td><pre><span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="16"></td><td><pre> </pre></td></tr><tr><td data-num="17"></td><td><pre><span class="token variable">$test1</span> <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">people</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="18"></td><td><pre><span class="token function">var_dump</span><span class="token punctuation">(</span><span class="token variable">$test1</span><span class="token operator">-></span><span class="token function">getByBus</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></pre></td></tr></table></figure><h4 id="调用父类构造方法"><a class="anchor" href="#调用父类构造方法">#</a> 调用父类构造方法</h4>
<p>PHP 不会再子类的构造方法中自动调用父类的构造方法。要执行父类的构造方法,需要再子类的构造方法中 <code>parent::__construct()</code> .</p>
<figure class="highlight php"><figcaption data-lang="PHP"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token keyword">class</span> <span class="token class-name-definition class-name">baseClass</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="2"></td><td><pre> <span class="token keyword">function</span> <span class="token function-definition function">__construct</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="3"></td><td><pre> <span class="token keyword">print</span> <span class="token string double-quoted-string">"BaseClass 类中构造方法"</span> <span class="token operator">.</span> <span class="token string double-quoted-string">"\n"</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="4"></td><td><pre> <span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="5"></td><td><pre><span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="6"></td><td><pre><span class="token keyword">class</span> <span class="token class-name-definition class-name">SubClass</span> <span class="token keyword">extends</span> <span class="token class-name">baseClass</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="7"></td><td><pre> <span class="token keyword">function</span> <span class="token function-definition function">__construct</span><span class="token punctuation">(</span><span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="8"></td><td><pre> <span class="token punctuation">&#123;</span> <span class="token keyword static-context">parent</span><span class="token operator">::</span><span class="token function">__construct</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 子类构造方法不能自动调用父类的构造方法 </span></pre></td></tr><tr><td data-num="9"></td><td><pre> <span class="token keyword">print</span> <span class="token string double-quoted-string">"SubClass 类中的方法"</span><span class="token operator">.</span> <span class="token string double-quoted-string">"\n"</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="10"></td><td><pre> <span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="11"></td><td><pre><span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="12"></td><td><pre> </pre></td></tr><tr><td data-num="13"></td><td><pre><span class="token keyword">class</span> <span class="token class-name-definition class-name">OtherSubClass</span> <span class="token keyword">extends</span> <span class="token class-name">baseClass</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="14"></td><td><pre><span class="token comment">// 继承 baseClass 构造方法 </span></pre></td></tr><tr><td data-num="15"></td><td><pre><span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="16"></td><td><pre><span class="token comment">// 调用 BaseClass 构造方法 </span></pre></td></tr><tr><td data-num="17"></td><td><pre><span class="token variable">$obj</span> <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">baseClass</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="18"></td><td><pre><span class="token comment">// 调用 BaseClass、SubClass 构造方法 </span></pre></td></tr><tr><td data-num="19"></td><td><pre> </pre></td></tr><tr><td data-num="20"></td><td><pre><span class="token variable">$obj</span> <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SubClass</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> </pre></td></tr><tr><td data-num="21"></td><td><pre><span class="token comment">// 调用 BaseClass 构造方法 </span></pre></td></tr><tr><td data-num="22"></td><td><pre> </pre></td></tr><tr><td data-num="23"></td><td><pre><span class="token variable">$obj</span> <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">OtherSubClass</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></pre></td></tr></table></figure> ]]></description>
</item>
<item>
<guid isPermalink="true">https://www.naraci.top/post/5856.html</guid>
<title>JavaScript函数用法</title>
<link>https://www.naraci.top/post/5856.html</link>
<category term="JavaScript" scheme="https://www.naraci.top/categories/JavaScript/" />
<category term="JavaScript" scheme="https://www.naraci.top/tags/JavaScript/" />
<pubDate>Sat, 17 Dec 2022 23:35:01 +0800</pubDate>
<description><![CDATA[ <h1 id="javascript-函数语法"><a class="anchor" href="#javascript-函数语法">#</a> Javascript 函数语法</h1>
<p>函数是由事件驱动的或者当它被调用时执行的可重复使用的代码块。</p>
<p>函数包裹在花括号的代码块,前面使用函数名 funciton</p>
<figure class="highlight javascript"><figcaption data-lang="javascript"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token keyword">function</span> <span class="token function">hanshu</span> <span class="token punctuation">(</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="2"></td><td><pre><span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="3"></td><td><pre> <span class="token comment">// 执行代码</span></pre></td></tr><tr><td data-num="4"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="5"></td><td><pre>innerHTML <span class="token operator">=</span> hanshu <span class="token comment">// 在 js 文件这么写可以在 HTML 导入引用 js 文件即可</span></pre></td></tr></table></figure><p>Javascript 对大小写敏感。关键词 function 必须事小写的,并且必须以与函数名称相同的大小写来调用函数。</p>
<h1 id="调用带参数的函数"><a class="anchor" href="#调用带参数的函数">#</a> 调用带参数的函数</h1>
<p>在调用函数时,可以向其传递值,这些值被称为参数。</p>
<blockquote>
<p>例:myfunction (argumentl,argument2)<br />
变量和参数必须按一致顺序出现。第一个变量对应的是第一个被传递的参数的值。</p>
</blockquote>
<figure class="highlight javascript"><figcaption data-lang="javascript"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token comment">//HTML 文件</span></pre></td></tr><tr><td data-num="2"></td><td><pre><span class="token operator">&lt;</span>button onclick<span class="token operator">=</span><span class="token string">"hanshu('naraci','student')>点我&lt;/button>"</span> <span class="token comment">// 参数必须加单引号</span></pre></td></tr><tr><td data-num="3"></td><td><pre></pre></td></tr><tr><td data-num="4"></td><td><pre><span class="token comment">//js 文件</span></pre></td></tr><tr><td data-num="5"></td><td><pre></pre></td></tr><tr><td data-num="6"></td><td><pre><span class="token keyword">function</span> <span class="token function">myfunction</span><span class="token punctuation">(</span><span class="token parameter">name<span class="token punctuation">,</span>job</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="7"></td><td><pre><span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="8"></td><td><pre> <span class="token function">alert</span><span class="token punctuation">(</span><span class="token string">"欢迎"</span><span class="token operator">+</span>name<span class="token operator">+</span><span class="token string">"的"</span><span class="token operator">+</span><span class="token string">"访问"</span><span class="token operator">+</span><span class="token string">"他是"</span><span class="token operator">+</span>job<span class="token punctuation">)</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="9"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr></table></figure> ]]></description>
</item>
<item>
<guid isPermalink="true">https://www.naraci.top/post/59758.html</guid>
<title>JavaScript对象用法</title>
<link>https://www.naraci.top/post/59758.html</link>
<category term="JavaScript" scheme="https://www.naraci.top/categories/JavaScript/" />
<category term="JavaScript" scheme="https://www.naraci.top/tags/JavaScript/" />
<pubDate>Sat, 17 Dec 2022 23:35:01 +0800</pubDate>
<description><![CDATA[ <h1 id="javascript对象"><a class="anchor" href="#javascript对象">#</a> Javascript 对象</h1>
<p>在 JavaScript 中所有事物都是对象。<br />
对象也是一个变量,但对象可以包含多个值 (多个变量),每个值以 <code>name:value</code> 对呈现</p>
<figure class="highlight javascript"><figcaption data-lang="javascript"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token keyword">var</span> car <span class="token operator">=</span> <span class="token punctuation">&#123;</span><span class="token literal-property property">name</span><span class="token operator">:</span><span class="token string">"Fiat"</span><span class="token punctuation">,</span> <span class="token literal-property property">model</span><span class="token operator">:</span><span class="token number">500</span><span class="token punctuation">,</span> <span class="token literal-property property">color</span><span class="token operator">:</span><span class="token string">"white"</span><span class="token punctuation">&#125;</span><span class="token punctuation">;</span></pre></td></tr></table></figure><blockquote>
<p>以上三个值赋予变量 car</p>
</blockquote>
<h1 id="对象定义"><a class="anchor" href="#对象定义">#</a> 对象定义</h1>
<p>可以使用字符来定义和创建 JavaScript 对象:</p>
<figure class="highlight javascript"><figcaption data-lang="javascript"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token keyword">var</span> person <span class="token operator">=</span> <span class="token punctuation">&#123;</span><span class="token literal-property property">firstName</span><span class="token operator">:</span><span class="token string">"John"</span><span class="token punctuation">,</span> <span class="token literal-property property">lastName</span><span class="token operator">:</span><span class="token string">"Doe"</span><span class="token punctuation">,</span> <span class="token literal-property property">age</span><span class="token operator">:</span><span class="token number">50</span><span class="token punctuation">,</span> <span class="token literal-property property">eyeColor</span><span class="token operator">:</span><span class="token string">"blue"</span><span class="token punctuation">&#125;</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="2"></td><td><pre></pre></td></tr><tr><td data-num="3"></td><td><pre><span class="token comment">// 或者</span></pre></td></tr><tr><td data-num="4"></td><td><pre></pre></td></tr><tr><td data-num="5"></td><td><pre><span class="token keyword">var</span> person <span class="token operator">=</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="6"></td><td><pre> firstName<span class="token operator">:</span><span class="token string">"John"</span><span class="token punctuation">,</span> </pre></td></tr><tr><td data-num="7"></td><td><pre> lastName<span class="token operator">:</span><span class="token string">"Doe"</span><span class="token punctuation">,</span> </pre></td></tr><tr><td data-num="8"></td><td><pre> age<span class="token operator">:</span><span class="token number">50</span><span class="token punctuation">,</span> </pre></td></tr><tr><td data-num="9"></td><td><pre> eyeColor<span class="token operator">:</span><span class="token string">"blue"</span> </pre></td></tr><tr><td data-num="10"></td><td><pre><span class="token punctuation">&#125;</span><span class="token punctuation">;</span></pre></td></tr></table></figure><blockquote>
<p>定义 JavaScript 对象可以跨越多行,空格换行不是必须的:</p>
</blockquote>
<h1 id="对象属性"><a class="anchor" href="#对象属性">#</a> 对象属性</h1>
<p>可以说是”JavaScript“对象是变量的容器。<br />
但是,我们通常认为”JavaScript” 对象是键值对的容器。<br />
键值对通常写法为 <code>name:value</code> (键与值以冒号分割)。<br />
键值对在 JavaScript 对象通常称为<em><strong>对象属性</strong></em><br />
对象键值对的写法类似于:</p>
<ul>
<li>PHP 中关联的数组</li>
<li>Python 中的字典</li>
<li>C 语言中的哈希表</li>
<li>Java 中的哈希映射</li>
<li>Ruby 和 perl 中的哈希表</li>
</ul>
<h1 id="访问对象属性"><a class="anchor" href="#访问对象属性">#</a> 访问对象属性</h1>
<p>第一种:</p>
<blockquote>
<p><code>person.lastName</code></p>
</blockquote>
<figure class="highlight javascript"><figcaption data-lang="javascript"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token keyword">var</span> person <span class="token operator">=</span> <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="2"></td><td><pre> <span class="token literal-property property">firstName</span> <span class="token operator">:</span> <span class="token string">"John"</span><span class="token punctuation">,</span></pre></td></tr><tr><td data-num="3"></td><td><pre> <span class="token literal-property property">lastName</span> <span class="token operator">:</span> <span class="token string">"Doe"</span><span class="token punctuation">,</span></pre></td></tr><tr><td data-num="4"></td><td><pre> <span class="token literal-property property">id</span> <span class="token operator">:</span> <span class="token number">5566</span></pre></td></tr><tr><td data-num="5"></td><td><pre><span class="token punctuation">&#125;</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="6"></td><td><pre>document<span class="token punctuation">.</span><span class="token function">getElementById</span><span class="token punctuation">(</span><span class="token string">"demo"</span><span class="token punctuation">)</span><span class="token punctuation">.</span>innerHTML <span class="token operator">=</span></pre></td></tr><tr><td data-num="7"></td><td><pre> person<span class="token punctuation">.</span>firstName <span class="token operator">+</span> <span class="token string">" "</span> <span class="token operator">+</span> person<span class="token punctuation">.</span>lastName<span class="token punctuation">;</span></pre></td></tr></table></figure><p>第二种:</p>
<blockquote>
<p>'person[&quot;lastName&quot;]'</p>
</blockquote>
<figure class="highlight javascript"><figcaption data-lang="javascript"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token keyword">var</span> person <span class="token operator">=</span> <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="2"></td><td><pre> <span class="token literal-property property">firstName</span><span class="token operator">:</span> <span class="token string">"John"</span><span class="token punctuation">,</span></pre></td></tr><tr><td data-num="3"></td><td><pre> <span class="token literal-property property">lastName</span> <span class="token operator">:</span> <span class="token string">"Doe"</span><span class="token punctuation">,</span></pre></td></tr><tr><td data-num="4"></td><td><pre> <span class="token literal-property property">id</span> <span class="token operator">:</span> <span class="token number">5566</span><span class="token punctuation">,</span></pre></td></tr><tr><td data-num="5"></td><td><pre> <span class="token function-variable function">fullName</span> <span class="token operator">:</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="6"></td><td><pre> <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="7"></td><td><pre> <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">.</span>firstName <span class="token operator">+</span> <span class="token string">" "</span> <span class="token operator">+</span> <span class="token keyword">this</span><span class="token punctuation">.</span>lastName<span class="token punctuation">;</span></pre></td></tr><tr><td data-num="8"></td><td><pre> <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="9"></td><td><pre><span class="token punctuation">&#125;</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="10"></td><td><pre>document<span class="token punctuation">.</span><span class="token function">getElementById</span><span class="token punctuation">(</span><span class="token string">"demo"</span><span class="token punctuation">)</span><span class="token punctuation">.</span>innerHTML <span class="token operator">=</span> person<span class="token punctuation">.</span><span class="token function">fullName</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></pre></td></tr></table></figure><p>对象的方法定义了一个函数,并作为对象的属性存储。</p>
<p>对象方法通过添加 () 调用 (作为一个函数)。</p>
<p>该实例访问了 person 对象的 fullName () 方法:</p>
<h1 id="访问对象方法"><a class="anchor" href="#访问对象方法">#</a> 访问对象方法</h1>
<p>可以使用以下语法创建对象方法:</p>
<figure class="highlight javascript"><figcaption data-lang="javascript"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token function-variable function">methodName</span> <span class="token operator">:</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="2"></td><td><pre> <span class="token comment">// 代码</span></pre></td></tr><tr><td data-num="3"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr></table></figure><blockquote>
<p><strong>实列</strong>:可以使用以下语法访问对象方法:</p>
</blockquote>
<p><code>objectName:function() &#123;&#125;</code></p>
<figure class="highlight javascript"><figcaption data-lang="javascript"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token keyword">var</span> person <span class="token operator">=</span> <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="2"></td><td><pre> <span class="token literal-property property">firstName</span><span class="token operator">:</span> <span class="token string">"John"</span><span class="token punctuation">,</span></pre></td></tr><tr><td data-num="3"></td><td><pre> <span class="token literal-property property">lastName</span> <span class="token operator">:</span> <span class="token string">"Doe"</span><span class="token punctuation">,</span></pre></td></tr><tr><td data-num="4"></td><td><pre> <span class="token literal-property property">id</span> <span class="token operator">:</span> <span class="token number">5566</span><span class="token punctuation">,</span></pre></td></tr><tr><td data-num="5"></td><td><pre> <span class="token function-variable function">fullName</span> <span class="token operator">:</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="6"></td><td><pre> <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="7"></td><td><pre> <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">.</span>firstName <span class="token operator">+</span> <span class="token string">" "</span> <span class="token operator">+</span> <span class="token keyword">this</span><span class="token punctuation">.</span>lastName<span class="token punctuation">;</span></pre></td></tr><tr><td data-num="8"></td><td><pre> <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="9"></td><td><pre><span class="token punctuation">&#125;</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="10"></td><td><pre>document<span class="token punctuation">.</span><span class="token function">getElementById</span><span class="token punctuation">(</span><span class="token string">"demo"</span><span class="token punctuation">)</span><span class="token punctuation">.</span>innerHTML <span class="token operator">=</span> person<span class="token punctuation">.</span><span class="token function">fullName</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></pre></td></tr></table></figure> ]]></description>
</item>
<item>
<guid isPermalink="true">https://www.naraci.top/post/4a3bb1da.html</guid>
<title>学习T签到接口</title>
<link>https://www.naraci.top/post/4a3bb1da.html</link>
<category term="Course" scheme="https://www.naraci.top/categories/Course/" />
<category term="Course" scheme="https://www.naraci.top/tags/Course/" />
<pubDate>Sat, 10 Dec 2022 23:35:01 +0800</pubDate>
<description><![CDATA[ <h2 id="接口"><a class="anchor" href="#接口">#</a> 接口:</h2>
<figure class="highlight url"><figcaption data-lang="url"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token scheme">http<span class="token scheme-delimiter">:</span></span><span class="token authority"><span class="token authority-delimiter">//</span><span class="token host"><span class="token ipv4-address">112.124.65.228</span></span><span class="token port-segment"><span class="token port-delimiter">:</span><span class="token port">78</span></span></span><span class="token path"><span class="token path-separator">/</span>main.php</span><span class="token query"><span class="token query-delimiter">?</span><span class="token pair"><span class="token key">account</span>=</span></span>账号&amp;password=密码</pre></td></tr></table></figure><h2 id="如何使用接口"><a class="anchor" href="#如何使用接口">#</a> 如何使用接口?</h2>
<p>在 url 链接对应文字描述替换成你的参数点击访问即可!</p>
<h3 id="如何让他全自动运行呢"><a class="anchor" href="#如何让他全自动运行呢">#</a> 如何让他全自动运行呢?</h3>
<p>填写好参数后将 url 链接放至监控平台定时访 url 即可!<br />
<img data-src="http://image.naraci.top/2022/05/19/53bc5c5a81f22.png" alt="" /></p>
]]></description>
</item>
<item>
<guid isPermalink="true">https://www.naraci.top/post/f93b2adf.html</guid>
<title>网络爬虫--Python</title>
<link>https://www.naraci.top/post/f93b2adf.html</link>
<category term="Python" scheme="https://www.naraci.top/categories/Python/" />
<category term="Python" scheme="https://www.naraci.top/tags/Python/" />
<pubDate>Wed, 23 Nov 2022 23:35:01 +0800</pubDate>
<description><![CDATA[ <h1 id="库"><a class="anchor" href="#库">#</a> 库</h1>
<p>request:自动爬取 HTML 页面,自动网络请求提交<br />
robots.txt: 网络爬虫排除标准<br />
beautiful soup:解析 HTML 页面<br />
Re: 正则表达式(用于提取需要的信息)</p>
<h2 id="request方法"><a class="anchor" href="#request方法">#</a> request 方法</h2>
<p>requests.request (): 构造一个请求支撑以下各方法的基础方法<br />
requests.get (): 获取 HTML 网页的主要方法对应 HTTP 的 get<br />
requests.head (): 获取 HTML 网页头部的信息方法对应 HTTP 的 head<br />
requests.post (): 向 HTML 网页提交 post 请求方法,对应 HTTP 的 post<br />
requests.put (): 向 HTML 提交 put 请求方法,对应 HTTP 的 put</p>
<h3 id="对象属性"><a class="anchor" href="#对象属性">#</a> 对象属性</h3>
<p>r.status_code: HTTP 请求返回状态,200 表示成功,404 表示失败<br />
r.txt: HTTP 响应内容的字符串方式,即 url 对应的页面内容<br />
re.encoding: 从 HTTP header 中猜测的响应内容编码形式<br />
r.apparent_encoding: 从内容分析出的响应编码方式(备用编码)<br />
r.content HTTP 响应内容的二进制形式</p>
<h1 id="handler处理器的基本使用"><a class="anchor" href="#handler处理器的基本使用">#</a> handler 处理器的基本使用</h1>
<ol>
<li>获取 hanlder 的方法<br />
opener = urllib.request.HttoHandler ()</li>
<li>获取 opener 对象<br />
opener = urllib.requst.build_opener (handler)</li>
<li>调用 open 方法<br />
response = opener.open (request)</li>
</ol>
<p>content = response.read().decode('utf-8')<br />
(可以使用代理)</p>
<h1 id="解析页面"><a class="anchor" href="#解析页面">#</a> 解析页面</h1>
<p><strong>常用的三个方法</strong></p>
<ol>
<li>Xpath // 获取网页源码的部分数据</li>
<li>JsonPath //</li>
<li>BeautifulSoup</li>
</ol>
<p><strong>1.Xapth</strong></p>
<table>
<thead>
<tr>
<th>表达式</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>nodename</td>
<td>选取此节点所有节点</td>
</tr>
<tr>
<td>/</td>
<td>从根节点选取。</td>
</tr>
<tr>
<td>//</td>
<td>从匹配选择的当前节点选择文档中的节点,而不考虑它们的位置</td>
</tr>
<tr>
<td>.</td>
<td>选取当前节点</td>
</tr>
<tr>
<td>..</td>
<td>选取当前节点的父节点</td>
</tr>
<tr>
<td>@</td>
<td>选取当前属性</td>
</tr>
</tbody>
</table>
<p><strong>选取未知节点</strong><br />
XPath 通配符可用来选取位置的 XML 元素。</p>
<table>
<thead>
<tr>
<th>通配符</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>*</td>
<td>匹配任何元素节点</td>
</tr>
<tr>
<td>@*</td>
<td>匹配任何属性节点</td>
</tr>
<tr>
<td>node()</td>
<td>匹配任何类型的节点</td>
</tr>
</tbody>
</table>
]]></description>
</item>
<item>
<guid isPermalink="true">https://www.naraci.top/post/5911a52a.html</guid>
<title>Java打印乘法表</title>
<link>https://www.naraci.top/post/5911a52a.html</link>
<category term="Java" scheme="https://www.naraci.top/categories/Java/" />
<category term="Java" scheme="https://www.naraci.top/tags/Java/" />
<pubDate>Tue, 08 Nov 2022 23:35:01 +0800</pubDate>
<description><![CDATA[ <figure class="highlight java"><figcaption data-lang="java"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token keyword">package</span> <span class="token namespace">top<span class="token punctuation">.</span>naraci<span class="token punctuation">.</span>shenzhaoyu</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="2"></td><td><pre></pre></td></tr><tr><td data-num="3"></td><td><pre><span class="token keyword">public</span> <span class="token keyword">class</span> 九九乘法表 <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="4"></td><td><pre> <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="5"></td><td><pre> <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> j <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span> j <span class="token operator">&lt;=</span> <span class="token number">9</span><span class="token punctuation">;</span> j<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="6"></td><td><pre> <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span> i <span class="token operator">&lt;=</span> j<span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="7"></td><td><pre> <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">print</span><span class="token punctuation">(</span>j<span class="token operator">+</span><span class="token string">"*"</span><span class="token operator">+</span>i<span class="token operator">+</span><span class="token string">"="</span><span class="token operator">+</span><span class="token punctuation">(</span>j<span class="token operator">*</span>i<span class="token punctuation">)</span><span class="token operator">+</span><span class="token string">"\t"</span><span class="token punctuation">)</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="8"></td><td><pre> <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="9"></td><td><pre> <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="10"></td><td><pre> <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="11"></td><td><pre> <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="12"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr></table></figure><p><img data-src="https://i.bmp.ovh/imgs/2021/12/6543c8283999b67b.png" alt=" " /></p>
]]></description>
</item>
<item>
<guid isPermalink="true">https://www.naraci.top/post/37627.html</guid>
<title>网络爬虫_写真网实战</title>
<link>https://www.naraci.top/post/37627.html</link>
<category term="Python" scheme="https://www.naraci.top/categories/Python/" />
<category term="Python" scheme="https://www.naraci.top/tags/Python/" />
<pubDate>Tue, 08 Nov 2022 23:35:01 +0800</pubDate>
<description><![CDATA[ <p>网络爬虫写真网实战,请勿大量爬取仅供参考学习<br />
需要再文件位置创建 meitu 文件夹用于存放图片</p>
<h1 id="代码"><a class="anchor" href="#代码">#</a> 代码</h1>
<figure class="highlight python"><figcaption data-lang="python"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token comment"># -*- coding: utf-8 -*- </span></pre></td></tr><tr><td data-num="2"></td><td><pre><span class="token comment"># @Time : 2022/10/26 7:41 </span></pre></td></tr><tr><td data-num="3"></td><td><pre><span class="token comment"># @Author : Naraci </span></pre></td></tr><tr><td data-num="4"></td><td><pre><span class="token comment"># @File : 写真优化重构版.py </span></pre></td></tr><tr><td data-num="5"></td><td><pre> </pre></td></tr><tr><td data-num="6"></td><td><pre><span class="token keyword">import</span> parsel </pre></td></tr><tr><td data-num="7"></td><td><pre><span class="token keyword">import</span> requests </pre></td></tr><tr><td data-num="8"></td><td><pre> </pre></td></tr><tr><td data-num="9"></td><td><pre>headers <span class="token operator">=</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="10"></td><td><pre> <span class="token string">'User-Agent'</span><span class="token punctuation">:</span> <span class="token string">'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 '</span> </pre></td></tr><tr><td data-num="11"></td><td><pre> <span class="token string">'Safari/537.36 '</span><span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="12"></td><td><pre> </pre></td></tr><tr><td data-num="13"></td><td><pre> </pre></td></tr><tr><td data-num="14"></td><td><pre><span class="token keyword">def</span> <span class="token function">url_request</span><span class="token punctuation">(</span>url<span class="token punctuation">)</span><span class="token punctuation">:</span> </pre></td></tr><tr><td data-num="15"></td><td><pre> request <span class="token operator">=</span> requests<span class="token punctuation">.</span>get<span class="token punctuation">(</span>url<span class="token operator">=</span>url<span class="token punctuation">,</span> headers<span class="token operator">=</span>headers<span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="16"></td><td><pre> <span class="token comment"># 设置编码格式防止乱码 </span></pre></td></tr><tr><td data-num="17"></td><td><pre> request<span class="token punctuation">.</span>encoding <span class="token operator">=</span> <span class="token string">'utf-8'</span> </pre></td></tr><tr><td data-num="18"></td><td><pre> html_text <span class="token operator">=</span> request<span class="token punctuation">.</span>text </pre></td></tr><tr><td data-num="19"></td><td><pre> <span class="token comment"># 转换数据类型 </span></pre></td></tr><tr><td data-num="20"></td><td><pre> parse_forats <span class="token operator">=</span> parsel<span class="token punctuation">.</span>Selector<span class="token punctuation">(</span>html_text<span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="21"></td><td><pre> parse_forats_list <span class="token operator">=</span> parse_forats<span class="token punctuation">.</span>xpath<span class="token punctuation">(</span><span class="token string">'//section//div//ul//span/text()'</span><span class="token punctuation">)</span><span class="token punctuation">.</span>getall<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">]</span> <span class="token comment"># 取该页面总页数 </span></pre></td></tr><tr><td data-num="22"></td><td><pre> num_list <span class="token operator">=</span> <span class="token punctuation">[</span>i <span class="token keyword">for</span> i <span class="token keyword">in</span> parse_forats_list <span class="token keyword">if</span> <span class="token builtin">str</span><span class="token punctuation">.</span>isdigit<span class="token punctuation">(</span>i<span class="token punctuation">)</span><span class="token punctuation">]</span> <span class="token comment"># Python isdigit () 方法检测字符串是否只由数字组成。返回 True or False. </span></pre></td></tr><tr><td data-num="23"></td><td><pre> add_list <span class="token operator">=</span> <span class="token string">''</span> </pre></td></tr><tr><td data-num="24"></td><td><pre> <span class="token keyword">for</span> i <span class="token keyword">in</span> num_list<span class="token punctuation">:</span> </pre></td></tr><tr><td data-num="25"></td><td><pre> add_list <span class="token operator">=</span> add_list <span class="token operator">+</span> i </pre></td></tr><tr><td data-num="26"></td><td><pre> </pre></td></tr><tr><td data-num="27"></td><td><pre> number_end <span class="token operator">=</span> <span class="token builtin">int</span><span class="token punctuation">(</span>add_list<span class="token punctuation">)</span> <span class="token comment"># 转换成整数类型 </span></pre></td></tr><tr><td data-num="28"></td><td><pre> <span class="token comment"># 页面地址 https://www.wxept.com/qqmn/rbmn/page/2 html_url = url </span></pre></td></tr><tr><td data-num="29"></td><td><pre> <span class="token comment"># 遍历每个页面地址 </span></pre></td></tr><tr><td data-num="30"></td><td><pre> <span class="token keyword">for</span> page <span class="token keyword">in</span> <span class="token builtin">range</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> number_end <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">:</span> </pre></td></tr><tr><td data-num="31"></td><td><pre> <span class="token keyword">if</span> page <span class="token operator">==</span> <span class="token number">1</span><span class="token punctuation">:</span> </pre></td></tr><tr><td data-num="32"></td><td><pre> request_url <span class="token operator">=</span> html_url </pre></td></tr><tr><td data-num="33"></td><td><pre> <span class="token keyword">else</span><span class="token punctuation">:</span> </pre></td></tr><tr><td data-num="34"></td><td><pre> request_url <span class="token operator">=</span> html_url <span class="token operator">+</span> <span class="token string">'/page/'</span> <span class="token operator">+</span> <span class="token builtin">str</span><span class="token punctuation">(</span>page<span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="35"></td><td><pre> <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">'正在下载:'</span> <span class="token operator">+</span> request_url <span class="token operator">+</span> <span class="token string">'页面!'</span><span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="36"></td><td><pre> <span class="token comment"># for page_list in range(1, number_end + 1): </span></pre></td></tr><tr><td data-num="37"></td><td><pre> request_url<span class="token punctuation">.</span>encode<span class="token punctuation">(</span><span class="token string">'utf-8'</span><span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="38"></td><td><pre> url_list <span class="token operator">=</span> requests<span class="token punctuation">.</span>get<span class="token punctuation">(</span>url<span class="token operator">=</span>request_url<span class="token punctuation">,</span> headers<span class="token operator">=</span>headers<span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="39"></td><td><pre> selector <span class="token operator">=</span> url_list<span class="token punctuation">.</span>text </pre></td></tr><tr><td data-num="40"></td><td><pre> selector <span class="token operator">=</span> parsel<span class="token punctuation">.</span>Selector<span class="token punctuation">(</span>selector<span class="token punctuation">)</span> <span class="token comment"># 转换数据类型 </span></pre></td></tr><tr><td data-num="41"></td><td><pre> content <span class="token operator">=</span> selector<span class="token punctuation">.</span>xpath<span class="token punctuation">(</span><span class="token string">'//div//div/article'</span><span class="token punctuation">)</span> <span class="token comment"># 获取所有需要的标签 </span></pre></td></tr><tr><td data-num="42"></td><td><pre> <span class="token keyword">for</span> article <span class="token keyword">in</span> content<span class="token punctuation">:</span> </pre></td></tr><tr><td data-num="43"></td><td><pre> pic_title <span class="token operator">=</span> article<span class="token punctuation">.</span>xpath<span class="token punctuation">(</span><span class="token string">'./h2/a/text()'</span><span class="token punctuation">)</span><span class="token punctuation">.</span>get<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment"># 套图标题 用于命名文件夹 返回为对象属性需要用 get 取出来 </span></pre></td></tr><tr><td data-num="44"></td><td><pre> pic_url <span class="token operator">=</span> article<span class="token punctuation">.</span>xpath<span class="token punctuation">(</span><span class="token string">'./h2/a/@href'</span><span class="token punctuation">)</span><span class="token punctuation">.</span>get<span class="token punctuation">(</span><span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="45"></td><td><pre> <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">'已将相册:'</span> <span class="token operator">+</span> pic_title <span class="token operator">+</span> <span class="token string">'添加到队列!'</span><span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="46"></td><td><pre> <span class="token comment"># pic_url = 'https://www.wxept.com/8762.html' </span></pre></td></tr><tr><td data-num="47"></td><td><pre> <span class="token comment"># # pic_url = 'https://www.wxept.com/8879.html' # 发送相册页面地址 </span></pre></td></tr><tr><td data-num="48"></td><td><pre> response_pic <span class="token operator">=</span> requests<span class="token punctuation">.</span>get<span class="token punctuation">(</span>url<span class="token operator">=</span>pic_url<span class="token punctuation">,</span> headers<span class="token operator">=</span>headers<span class="token punctuation">)</span><span class="token punctuation">.</span>text </pre></td></tr><tr><td data-num="49"></td><td><pre> <span class="token comment"># 获取相册页面所有页数 </span></pre></td></tr><tr><td data-num="50"></td><td><pre> selector_2 <span class="token operator">=</span> parsel<span class="token punctuation">.</span>Selector<span class="token punctuation">(</span>response_pic<span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="51"></td><td><pre> img_url <span class="token operator">=</span> selector_2<span class="token punctuation">.</span>xpath<span class="token punctuation">(</span><span class="token string">'//div/a/span'</span><span class="token punctuation">)</span><span class="token punctuation">.</span>getall<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token operator">-</span><span class="token number">2</span><span class="token punctuation">]</span> </pre></td></tr><tr><td data-num="52"></td><td><pre> num_list <span class="token operator">=</span> <span class="token punctuation">[</span>i <span class="token keyword">for</span> i <span class="token keyword">in</span> img_url <span class="token keyword">if</span> <span class="token builtin">str</span><span class="token punctuation">.</span>isdigit<span class="token punctuation">(</span>i<span class="token punctuation">)</span><span class="token punctuation">]</span> <span class="token comment"># Python isdigit () 方法检测字符串是否只由数字组成。返回 True or False. </span></pre></td></tr><tr><td data-num="53"></td><td><pre> add_list <span class="token operator">=</span> <span class="token string">''</span> </pre></td></tr><tr><td data-num="54"></td><td><pre> number_list <span class="token operator">=</span> pic_url<span class="token punctuation">.</span>split<span class="token punctuation">(</span><span class="token string">'.html'</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span> </pre></td></tr><tr><td data-num="55"></td><td><pre> <span class="token comment"># # 遍历出所有页面 </span></pre></td></tr><tr><td data-num="56"></td><td><pre> <span class="token keyword">for</span> i <span class="token keyword">in</span> num_list<span class="token punctuation">:</span> </pre></td></tr><tr><td data-num="57"></td><td><pre> add_list <span class="token operator">=</span> add_list <span class="token operator">+</span> i </pre></td></tr><tr><td data-num="58"></td><td><pre> number_end <span class="token operator">=</span> <span class="token builtin">int</span><span class="token punctuation">(</span>add_list<span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="59"></td><td><pre> <span class="token keyword">for</span> page <span class="token keyword">in</span> <span class="token builtin">range</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> number_end <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">:</span> </pre></td></tr><tr><td data-num="60"></td><td><pre> <span class="token keyword">if</span> page <span class="token operator">==</span> <span class="token number">1</span><span class="token punctuation">:</span> </pre></td></tr><tr><td data-num="61"></td><td><pre> request_html_url <span class="token operator">=</span> number_list <span class="token operator">+</span> <span class="token string">'.html'</span> </pre></td></tr><tr><td data-num="62"></td><td><pre> <span class="token keyword">else</span><span class="token punctuation">:</span> </pre></td></tr><tr><td data-num="63"></td><td><pre> request_html_url <span class="token operator">=</span> number_list <span class="token operator">+</span> <span class="token string">'.html/'</span> <span class="token operator">+</span> <span class="token builtin">str</span><span class="token punctuation">(</span>page<span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="64"></td><td><pre> <span class="token keyword">print</span><span class="token punctuation">(</span>request_html_url<span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="65"></td><td><pre> <span class="token comment">#解析图片地址 </span></pre></td></tr><tr><td data-num="66"></td><td><pre> response_pic <span class="token operator">=</span> requests<span class="token punctuation">.</span>get<span class="token punctuation">(</span>url<span class="token operator">=</span>request_html_url<span class="token punctuation">,</span> headers<span class="token operator">=</span>headers<span class="token punctuation">)</span><span class="token punctuation">.</span>text </pre></td></tr><tr><td data-num="67"></td><td><pre> selector_2 <span class="token operator">=</span> parsel<span class="token punctuation">.</span>Selector<span class="token punctuation">(</span>response_pic<span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="68"></td><td><pre> img_url <span class="token operator">=</span> selector_2<span class="token punctuation">.</span>xpath<span class="token punctuation">(</span><span class="token string">'//section//article//a/img/@src'</span><span class="token punctuation">)</span><span class="token punctuation">.</span>getall<span class="token punctuation">(</span><span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="69"></td><td><pre> <span class="token keyword">for</span> pic_url <span class="token keyword">in</span> img_url<span class="token punctuation">:</span> </pre></td></tr><tr><td data-num="70"></td><td><pre> <span class="token comment"># 发送图片链接请求,获取图片数据以二进制数据保存 </span></pre></td></tr><tr><td data-num="71"></td><td><pre> img_data <span class="token operator">=</span> requests<span class="token punctuation">.</span>get<span class="token punctuation">(</span>url<span class="token operator">=</span>pic_url<span class="token punctuation">,</span> headers<span class="token operator">=</span>headers<span class="token punctuation">)</span><span class="token punctuation">.</span>content </pre></td></tr><tr><td data-num="72"></td><td><pre> <span class="token comment"># 数据保存 </span></pre></td></tr><tr><td data-num="73"></td><td><pre> fil_name <span class="token operator">=</span> pic_url<span class="token punctuation">.</span>split<span class="token punctuation">(</span><span class="token string">'/'</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">]</span> <span class="token comment"># 获取图片名字 </span></pre></td></tr><tr><td data-num="74"></td><td><pre> <span class="token keyword">with</span> <span class="token builtin">open</span><span class="token punctuation">(</span><span class="token string">'meitudownload\\'</span> <span class="token operator">+</span> fil_name<span class="token punctuation">,</span> mode<span class="token operator">=</span><span class="token string">'wb'</span><span class="token punctuation">)</span> <span class="token keyword">as</span> fp<span class="token punctuation">:</span> <span class="token comment"># wb 二进制 </span></pre></td></tr><tr><td data-num="75"></td><td><pre> fp<span class="token punctuation">.</span>write<span class="token punctuation">(</span>img_data<span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="76"></td><td><pre> <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">'下载完成:'</span> <span class="token operator">+</span> fil_name<span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="77"></td><td><pre> </pre></td></tr><tr><td data-num="78"></td><td><pre> </pre></td></tr><tr><td data-num="79"></td><td><pre><span class="token keyword">if</span> __name__ <span class="token operator">==</span> <span class="token string">'__main__'</span><span class="token punctuation">:</span> </pre></td></tr><tr><td data-num="80"></td><td><pre> <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">'请在文件目录手动新建meitudownload目录'</span><span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="81"></td><td><pre> <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">'在下面网址复制url粘贴值下方:https://www.wxept.com/qqmn/'</span><span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="82"></td><td><pre> put_url <span class="token operator">=</span> <span class="token builtin">input</span><span class="token punctuation">(</span><span class="token string">'请输入正确分类页面url:'</span><span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="83"></td><td><pre> <span class="token comment"># url = 'https://www.wxept.com/qqmn/dlmn' </span></pre></td></tr><tr><td data-num="84"></td><td><pre> url <span class="token operator">=</span> put_url </pre></td></tr><tr><td data-num="85"></td><td><pre> url_request<span class="token punctuation">(</span>url<span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="86"></td><td><pre> <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">'全部下载成功!'</span><span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="87"></td><td><pre> </pre></td></tr><tr><td data-num="88"></td><td><pre> <span class="token comment"># 文件根目录手动创建 meitu 文件夹</span></pre></td></tr></table></figure><h1 id="文件下载"><a class="anchor" href="#文件下载">#</a> 文件下载</h1>
<p>源代码和 exe 成品文件<span class="exturl" data-url="aHR0cDovL3Bhbi5uYXJhY2kudG9wL3MvWDN6czY=">点击下载</span></p>
]]></description>
</item>
<item>
<guid isPermalink="true">https://www.naraci.top/post/21093.html</guid>
<title>网络Python用法速查</title>
<link>https://www.naraci.top/post/21093.html</link>
<category term="python" scheme="https://www.naraci.top/categories/python/" />
<category term="python" scheme="https://www.naraci.top/tags/python/" />
<pubDate>Mon, 07 Nov 2022 23:35:01 +0800</pubDate>
<description><![CDATA[ <h1 id="字符串高级"><a class="anchor" href="#字符串高级">#</a> 字符串高级</h1>
<p>字符串的常见操作</p>
<ul>
<li>获取长度 :len len 函数可以获取字符串的长度</li>
<li>查找内容 :find 查找指定内容在字符串中是否存在,如果存在就返回改内容在字符串中第一次出现的位置索引值,如果不存在返回 1</li>
<li>判断:startswith,endswith 判断字符串是不是以谁谁谁开头 / 结尾</li>
<li>计算出现的次数:count 返回 str 在 start 和 end 之间 在 mystr 里面出现的次数</li>
<li>替换内容:replace 替换字符的内容切割字符串</li>
<li>修改大小写: upper,lower 将字符串中的大小写互换</li>
<li>空格处理: strip 去空格</li>
<li>字符串拼接: join 字符串拼接</li>
</ul>
<h1 id="列表的高级"><a class="anchor" href="#列表的高级">#</a> 列表的高级</h1>
<p>列表的增删改查</p>
<ul>
<li>append: 在末尾添加元素</li>
<li>insert : 在指定位置插入元素</li>
<li>extend:合并两个列表</li>
<li>修改 :通过下标来修改</li>
<li>del:根据下标删除</li>
<li>pop:删除最后一个元素</li>
<li>remov:根据元素的值删除元素</li>
</ul>
<h1 id="查找高级"><a class="anchor" href="#查找高级">#</a> 查找高级</h1>
<ul>
<li>in : 用法例子:if i in list (): // 可以理解为 i 变量是否在 list 的里面(判断这个元素是否在某个列表中)</li>
<li>not in : 和上面的 in 是相反的意思是相反的意思用法和 in 一样</li>
</ul>
<h1 id="切片"><a class="anchor" href="#切片">#</a> 切片</h1>
<p>使用列表下标来切<br />
s = 'china'<br />
print (s [2]) // 会打印出 i<br />
print (s [:3]) // 会打印出 chin<br />
步长默认为 1 也可以不写</p>
<h1 id="字典的高级用法"><a class="anchor" href="#字典的高级用法">#</a> 字典的高级用法</h1>
<p>获取字典内的值两个方法</p>
<ol>
<li>字典名 [’字典内的值]</li>
<li>字典名.get (' 字典内的值 ')</li>
</ol>
<blockquote>
<p>两者不同的是当字典内没有该值 1 方法会报错而 2 方法会返回 None 空的值</p>
</blockquote>
<p>字典修改:直接字典名 [' 对应的值 '] = 要修改的值</p>
<p>字典的添加:字典名 [' 值 '] = 要添加的值 // 如果字典里面没有这个值则会添加,如果有则会成为修改。</p>
<p>字典中的删除:有两个方法一个是 del 另一个是 clear 两者虽然都是删除但是作用还是有区别的,del 是删除指定的值和删除整个字典,clear 则是清空字典内容但是保留字典对象</p>
<p>遍历:就是将数据一个一个输出</p>
<h1 id="函数"><a class="anchor" href="#函数">#</a> 函数</h1>
<p>def 声明函数<br />
格式:def 函数名 (可以放形参)<br />
而调用函数<br />
格式:def 函数名 (放实参)</p>
<p>函数的局部变量和全局变量</p>
<p>局部变量:在函数内部定义的变量叫做局部变量<br />
全局变量:在函数外部定义的变量称之为全局变量,它可以在函数内使用也可以在函数外部使用。</p>
<p>文件的操作 I/o</p>
<p>Python 打开和关闭文件<br />
open 函数<br />
打开文件<br />
格式:open (文件路径,访问模式)<br />
关闭文件<br />
格式:<br />
fp = open (文件路径,访问模式) // 打开文件<br />
fp. write (写入文件内容) // 写入文件<br />
fp.close () // 关闭文件<br />
fp.read () // 读取文件内容<br />
read 是按一个字节一个字节读取的效率比较慢<br />
readline 是按一行一行读取的但是返回的是一个列表</p>
<p>访问模式<br />
w : 读写<br />
r: 仅读<br />
a: 在文件内容后面追加内容,如果没有该文件则会创建文件并写入内容<br />
r+: 打开文件并将指针移到文件的开头,若没有该文件则会创建新的文件<br />
wb: 以二进制模式打开文件用于读写,若没有该文件则会创建新的文件并写入</p>
<p>urlib 六个使用方法</p>
]]></description>
</item>
<item>
<guid isPermalink="true">https://www.naraci.top/post/85.html</guid>
<title>CSS笔记</title>
<link>https://www.naraci.top/post/85.html</link>
<category term="css" scheme="https://www.naraci.top/categories/css/" />
<category term="css" scheme="https://www.naraci.top/tags/css/" />
<pubDate>Thu, 03 Nov 2022 23:35:01 +0800</pubDate>
<description><![CDATA[ <h1 id="文本对齐方式"><a class="anchor" href="#文本对齐方式">#</a> 文本对齐方式</h1>
<p>text-align:center 居中<br />
text-align:right 向右对齐<br />
text-align:jusitfy 每行被展开为宽度相等,左,右外边距是对齐。</p>
<h1 id="文本修饰"><a class="anchor" href="#文本修饰">#</a> 文本修饰</h1>
<p>text-decoration:none 用于删除下划线<br />
text-indent:50px 文本缩进用来指定文本的第一行缩进。<br />
font-style:normal 正常显示文本<br />
font-style:italic 以斜体字显示的文字<br />
font-size 控制文字大小</p>
<h1 id="链接样式"><a class="anchor" href="#链接样式">#</a> 链接样式</h1>
<p>a:link {color:#000000;} /* 未访问链接 */<br />
a:visited {color:#00FF00;} /* 已访问链接 <em>/<br />
a:hover {color:#FF00FF;} /</em> 鼠标移动到链接上 <em>/<br />
a:active {color:#0000FF;} /</em> 鼠标点击时 */<br />
<strong> 常见的链接样式</strong></p>
<p>link 链接<br />
visited 访问<br />
hover 悬停<br />
active 活动</p>
<h1 id="盒子模型box-model"><a class="anchor" href="#盒子模型box-model">#</a> 盒子模型(Box Model)</h1>
<p>盒子包含:<br />
外边距 - Margin:清除外边框的区域,外边距是透明的<br />
边框 - Border:围绕在内边距和外边距的边框<br />
内边距 - Padding:清除内容周围的区域,外边距是透明的<br />
实际内容 - Content:盒子的内容,显示文本和图像</p>
<p>总元素的宽度:宽度 + 左填充 + 右填充 + 左边框 + 右边框 + 左边距 + 右边距</p>
<p>总元素的高度:高度 + 顶部填充 + 底部填充 + 上边框 + 下边框 + 上边距 + 下边距</p>
<h1 id="border边框"><a class="anchor" href="#border边框">#</a> Border (边框)</h1>
<p><strong>border-style</strong><br />
dotted:定义一个点线边框<br />
dashed:定义一个虚线边框<br />
solid:定义一个实体边框<br />
double:定义两个边框,两个边框的宽度和 border-width 的值相同<br />
groove:定义 3D 沟槽边框,效果取决于边框的颜色值<br />
ridge:定义 3D 脊边框,效果取决于颜色值<br />
inset:定义一个 3D 的嵌入边框吗,效果取决于边框的颜色值<br />
outset:定义一个 3D 突出边框。效果取决于边框的颜色值</p>
<p><strong>边框 - 单独设置各边</strong><br />
border-top-style:dotted;<br />
border-right-style:solid;<br />
border-bottom-style:dotted;<br />
border-left-style:solid;</p>
<h1 id="css轮廓outline"><a class="anchor" href="#css轮廓outline">#</a> css 轮廓 (outline)</h1>
<p>轮框是绘制元素周期的一条线,位于边框边缘的外围,可以起到突出元素的作用。<br />
ps:outline 是不占空间的,既不会增加额外的 width 或者 height</p>
<p><strong>outline</strong>(在一个声明中设置所有的轮廓属性)<br />
值:<br />
_outline-color<br />
outline-style<br />
outline-width<br />
inherit</p>
<p><strong>outline-color</strong> (设置轮廓的颜色)<br />
值:<br />
color-name<br />
hex-number<br />
rgb-number<br />
_invert<br />
inherit</p>
<p><strong>outline-style</strong> (设置轮廓样式)<br />
值:</p>
<pre><code>none
dotted
dashed
solid
double
groove
ridge
inset
outset
</code></pre>
<p>inherit</p>
<p>outline-width(设置轮廓宽度)<br />
值:<br />
thin<br />
medium<br />
thick<br />
_length<br />
inherit</p>
]]></description>
</item>
<item>
<guid isPermalink="true">https://www.naraci.top/post/8c17a938.html</guid>
<title>用Python编写的抖音无水印视频代码</title>
<link>https://www.naraci.top/post/8c17a938.html</link>
<category term="Python" scheme="https://www.naraci.top/categories/Python/" />
<category term="Python" scheme="https://www.naraci.top/tags/Python/" />
<pubDate>Mon, 17 Oct 2022 23:35:01 +0800</pubDate>
<description><![CDATA[ <figure class="highlight python"><figcaption data-lang="python"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token comment"># author:Naraci </span></pre></td></tr><tr><td data-num="2"></td><td><pre><span class="token comment"># time:14:44 </span></pre></td></tr><tr><td data-num="3"></td><td><pre><span class="token comment"># file:DouYing_Video.py </span></pre></td></tr><tr><td data-num="4"></td><td><pre><span class="token comment"># IDE:PyCharm </span></pre></td></tr><tr><td data-num="5"></td><td><pre> </pre></td></tr><tr><td data-num="6"></td><td><pre><span class="token keyword">import</span> requests </pre></td></tr><tr><td data-num="7"></td><td><pre><span class="token keyword">import</span> re </pre></td></tr><tr><td data-num="8"></td><td><pre><span class="token keyword">import</span> os </pre></td></tr><tr><td data-num="9"></td><td><pre><span class="token keyword">import</span> unicodedata </pre></td></tr><tr><td data-num="10"></td><td><pre> </pre></td></tr><tr><td data-num="11"></td><td><pre><span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"欢迎使用奈良池DY无水印解析系统\n"</span><span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="12"></td><td><pre><span class="token keyword">if</span> os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>exists<span class="token punctuation">(</span><span class="token string">'D:/抖音无水印解析视频'</span><span class="token punctuation">)</span><span class="token punctuation">:</span> </pre></td></tr><tr><td data-num="13"></td><td><pre> wjml <span class="token operator">=</span> os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>exists </pre></td></tr><tr><td data-num="14"></td><td><pre> <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"检测到已有该目录"</span><span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="15"></td><td><pre><span class="token keyword">else</span><span class="token punctuation">:</span> </pre></td></tr><tr><td data-num="16"></td><td><pre> os<span class="token punctuation">.</span>makedirs<span class="token punctuation">(</span><span class="token string">"D:/抖音无水印解析视频"</span><span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="17"></td><td><pre> <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"以为您创建下载目录"</span><span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="18"></td><td><pre> </pre></td></tr><tr><td data-num="19"></td><td><pre>pre_savename <span class="token operator">=</span> <span class="token string">'D:/抖音无水印解析视频/'</span> </pre></td></tr><tr><td data-num="20"></td><td><pre>name <span class="token operator">=</span> <span class="token string">"下载成功文件已保存至"</span> </pre></td></tr><tr><td data-num="21"></td><td><pre> </pre></td></tr><tr><td data-num="22"></td><td><pre>headers <span class="token operator">=</span> <span class="token punctuation">&#123;</span> </pre></td></tr><tr><td data-num="23"></td><td><pre> <span class="token string">"user-agent"</span><span class="token punctuation">:</span> <span class="token string">"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "</span> </pre></td></tr><tr><td data-num="24"></td><td><pre> <span class="token string">"Chrome/99.0.4844.51 Safari/537.36 Edg/99.0.1150.30 "</span><span class="token punctuation">&#125;</span> </pre></td></tr><tr><td data-num="25"></td><td><pre> </pre></td></tr><tr><td data-num="26"></td><td><pre> </pre></td></tr><tr><td data-num="27"></td><td><pre><span class="token keyword">def</span> <span class="token function">UrlGet</span><span class="token punctuation">(</span>url<span class="token punctuation">)</span><span class="token punctuation">:</span> </pre></td></tr><tr><td data-num="28"></td><td><pre> <span class="token keyword">try</span><span class="token punctuation">:</span> </pre></td></tr><tr><td data-num="29"></td><td><pre> r <span class="token operator">=</span> requests<span class="token punctuation">.</span>get<span class="token punctuation">(</span>url<span class="token punctuation">,</span> timeout<span class="token operator">=</span><span class="token number">30</span><span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="30"></td><td><pre> r<span class="token punctuation">.</span>raise_for_status<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment"># 输出异常信息 </span></pre></td></tr><tr><td data-num="31"></td><td><pre> r<span class="token punctuation">.</span>encoding <span class="token operator">=</span> r<span class="token punctuation">.</span>apparent_encoding </pre></td></tr><tr><td data-num="32"></td><td><pre> <span class="token keyword">return</span> r<span class="token punctuation">.</span>text <span class="token comment"># 将网页信息内容返回给其他程序块 </span></pre></td></tr><tr><td data-num="33"></td><td><pre> <span class="token keyword">except</span><span class="token punctuation">:</span> </pre></td></tr><tr><td data-num="34"></td><td><pre> <span class="token keyword">return</span> <span class="token string">''</span> <span class="token comment"># 将异常内容返回空字符串 </span></pre></td></tr><tr><td data-num="35"></td><td><pre> </pre></td></tr><tr><td data-num="36"></td><td><pre> </pre></td></tr><tr><td data-num="37"></td><td><pre><span class="token keyword">def</span> <span class="token function">UrlHandle</span><span class="token punctuation">(</span>url<span class="token punctuation">)</span><span class="token punctuation">:</span> </pre></td></tr><tr><td data-num="38"></td><td><pre> shorturl <span class="token operator">=</span> re<span class="token punctuation">.</span>findall<span class="token punctuation">(</span><span class="token string">"https?://[a-z./A-Z0-9]+"</span><span class="token punctuation">,</span> url<span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="39"></td><td><pre> <span class="token keyword">if</span> <span class="token builtin">len</span><span class="token punctuation">(</span>shorturl<span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token number">1</span><span class="token punctuation">:</span> </pre></td></tr><tr><td data-num="40"></td><td><pre> VideoShoutUrl <span class="token operator">=</span> shorturl<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span> </pre></td></tr><tr><td data-num="41"></td><td><pre> url <span class="token operator">=</span> requests<span class="token punctuation">.</span>get<span class="token punctuation">(</span>VideoShoutUrl<span class="token punctuation">,</span> headers<span class="token operator">=</span>headers<span class="token punctuation">)</span><span class="token punctuation">.</span>url </pre></td></tr><tr><td data-num="42"></td><td><pre> VideoPage <span class="token operator">=</span> requests<span class="token punctuation">.</span>post<span class="token punctuation">(</span>url<span class="token operator">=</span>url<span class="token punctuation">,</span> headers<span class="token operator">=</span>headers<span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="43"></td><td><pre> <span class="token comment"># 匹配视频地址 </span></pre></td></tr><tr><td data-num="44"></td><td><pre> regular <span class="token operator">=</span> re<span class="token punctuation">.</span>findall<span class="token punctuation">(</span><span class="token string">'src(.*?)mp4'</span><span class="token punctuation">,</span> VideoPage<span class="token punctuation">.</span>text<span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span> </pre></td></tr><tr><td data-num="45"></td><td><pre> <span class="token comment"># 解码 </span></pre></td></tr><tr><td data-num="46"></td><td><pre> video_url <span class="token operator">=</span> requests<span class="token punctuation">.</span>utils<span class="token punctuation">.</span>unquote<span class="token punctuation">(</span>regular<span class="token punctuation">)</span><span class="token punctuation">.</span>replace<span class="token punctuation">(</span><span class="token string">'":"'</span><span class="token punctuation">,</span> <span class="token string">'https:'</span><span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="47"></td><td><pre> <span class="token comment"># title = re.findall('&lt;title data-react-helmet="true">(.*?)&lt;/title>', VideoPage.text)[0] </span></pre></td></tr><tr><td data-num="48"></td><td><pre> title <span class="token operator">=</span> re<span class="token punctuation">.</span>findall<span class="token punctuation">(</span><span class="token string">'&lt;title data-react-helmet="true">(.*?)&lt;/title>'</span><span class="token punctuation">,</span> VideoPage<span class="token punctuation">.</span>text<span class="token punctuation">,</span> re<span class="token punctuation">.</span>S<span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">.</span>replace<span class="token punctuation">(</span><span class="token string">'"\n"'</span><span class="token punctuation">,</span> <span class="token string">""</span><span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="49"></td><td><pre> </pre></td></tr><tr><td data-num="50"></td><td><pre> <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"正在下载:"</span><span class="token punctuation">,</span> title<span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="51"></td><td><pre> <span class="token comment"># 创建文件夹 </span></pre></td></tr><tr><td data-num="52"></td><td><pre> f <span class="token operator">=</span> <span class="token builtin">open</span><span class="token punctuation">(</span>pre_savename <span class="token operator">+</span> <span class="token string">"%s.mp4"</span> <span class="token operator">%</span> title<span class="token punctuation">,</span> mode<span class="token operator">=</span><span class="token string">"wb"</span><span class="token punctuation">)</span> <span class="token comment"># wb 表示写入的内容为非文本文件,VideoName 为视频标题 </span></pre></td></tr><tr><td data-num="53"></td><td><pre> f<span class="token punctuation">.</span>write<span class="token punctuation">(</span>requests<span class="token punctuation">.</span>get<span class="token punctuation">(</span>video_url<span class="token punctuation">,</span> headers<span class="token operator">=</span>headers<span class="token punctuation">)</span><span class="token punctuation">.</span>content<span class="token punctuation">)</span> <span class="token comment"># 向外取出图片数据,不是文本信息 </span></pre></td></tr><tr><td data-num="54"></td><td><pre> DiZhi <span class="token operator">=</span> name <span class="token operator">+</span> pre_savename </pre></td></tr><tr><td data-num="55"></td><td><pre> <span class="token keyword">print</span><span class="token punctuation">(</span>DiZhi<span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="56"></td><td><pre> </pre></td></tr><tr><td data-num="57"></td><td><pre> </pre></td></tr><tr><td data-num="58"></td><td><pre><span class="token keyword">if</span> __name__ <span class="token operator">==</span> <span class="token string">'__main__'</span><span class="token punctuation">:</span> </pre></td></tr><tr><td data-num="59"></td><td><pre> run <span class="token operator">=</span> <span class="token number">1</span> </pre></td></tr><tr><td data-num="60"></td><td><pre> <span class="token keyword">while</span> run <span class="token operator">==</span> <span class="token number">1</span><span class="token punctuation">:</span> </pre></td></tr><tr><td data-num="61"></td><td><pre> url <span class="token operator">=</span> <span class="token builtin">input</span><span class="token punctuation">(</span><span class="token string">"请输入视频链接:"</span><span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="62"></td><td><pre> <span class="token comment"># url = '5.15 yGi:/ 喜欢你 很喜欢你 特别喜欢你.@ta https://v.douyin.com/Ff1a79j/ 复制此链接,打开 Dou 音搜索,直接观看视频! ' html = UrlGet (url) </span></pre></td></tr><tr><td data-num="63"></td><td><pre> UrlHandle<span class="token punctuation">(</span>url<span class="token punctuation">)</span> </pre></td></tr><tr><td data-num="64"></td><td><pre> <span class="token keyword">print</span><span class="token punctuation">(</span>html<span class="token punctuation">)</span></pre></td></tr></table></figure><p>注意:本地需要有 Python 环境!</p>
]]></description>
</item>
<item>
<guid isPermalink="true">https://www.naraci.top/post/14702.html</guid>
<title>Python基础</title>
<link>https://www.naraci.top/post/14702.html</link>
<category term="python" scheme="https://www.naraci.top/categories/python/" />
<category term="python" scheme="https://www.naraci.top/tags/python/" />
<pubDate>Fri, 14 Oct 2022 23:35:01 +0800</pubDate>
<description><![CDATA[ <h1 id="变量"><a class="anchor" href="#变量">#</a> 变量</h1>
<p>直接赋值例如:<br />
a = 1<br />
b = 2<br />
注意:字符串赋值需加引号 “” 如 <code>c = &quot;刘强&quot;</code></p>
<h1 id="数据类型"><a class="anchor" href="#数据类型">#</a> 数据类型</h1>
<p>整数类型:int<br />
字符串类型:str<br />
浮点数:float<br />
等等..</p>
<h1 id="数组"><a class="anchor" href="#数组">#</a> 数组</h1>
<p>注意取单个字符需要从 0 开始计数例如<br />
''a,b,c,d&quot;--&gt;0,1,2,3<br />
若 <code>[:5]</code> --&gt; 则是从 1 开始计数</p>
<h1 id="字典"><a class="anchor" href="#字典">#</a> 字典</h1>
<p name:="" 张三,sex:男,age:="" 20="">var =</p>
<p>函数<br />
常用的 Python 内助的函数<br />
input ( ) 用于接收用户输入的数据<br />
print ( ) 用于打印数据</p>
<h1 id="判断语句"><a class="anchor" href="#判断语句">#</a> 判断语句</h1>
<p>假若<br />
a = 3<br />
b = 2<br />
如果 a 和 b 相等则会执行上面的语句反之执行下一行的<br />
if 判断条件:<br />
执行语句……<br />
else:<br />
执行语句……<br />
注意:缩进需注意</p>
<h1 id="循环语句"><a class="anchor" href="#循环语句">#</a> 循环语句</h1>
<p>while 语句 给定它一个值的范围等于,不等于或者大小于它都会一直运行直至超出或者小于给定值停止运行。<br />
<img data-src="https://www.runoob.com/wp-content/uploads/2014/05/006faQNTgw1f5wnm06h3ug30ci08cake.gif" alt="图片摘自与菜鸟教程" /></p>
<p>for 语句<br />
Python for 循环可以遍历任何序列的项目,如一个列表或者一个字符串<br />
可以循环字符串</p>
<figure class="highlight python"><figcaption data-lang="python"></figcaption><table><tr><td data-num="1"></td><td><pre>s <span class="token operator">=</span> <span class="token string">'china'</span></pre></td></tr><tr><td data-num="2"></td><td><pre><span class="token keyword">for</span> i <span class="token keyword">in</span> s<span class="token punctuation">:</span></pre></td></tr><tr><td data-num="3"></td><td><pre> <span class="token keyword">print</span><span class="token punctuation">(</span>i<span class="token punctuation">)</span></pre></td></tr></table></figure><blockquote>
<p>结果挨个换行打印出 china</p>
</blockquote>
<p>for i in range(5)<br />
含义是遍历 0-5 前一个结束会从 0 开始计数至数字 4 结束</p>
<p>若想从一计数那么需要加上参数<br />
for i in range (1,5)<br />
含有则是从 1 开始到 5 前一个数字结束<br />
会输出 1-4</p>
<p>for 语句里面还能包含三个值例如:<br />
for i in range(1, 10, 3)<br />
for i in range (起始值, 结束值, 步长)<br />
1 开始步长为 3<br />
1+3=4<br />
4+3=7<br />
7+3=10 // 但是只能 1-9 所以 10 不能输出<br />
则会打印 1 4 7<br />
** 应用场景:** 会爬取一个列表返回给我们<br />
循环一个列表<br />
例如:<br />
a_list = [' 周杰伦 ',' 林俊杰 ', ' 成龙 ']<br />
for i in a_list:<br />
print(i)<br />
break 语句<br />
break 语句用在 while 和 for 循环中。<br />
作用:停止执行后面的循环语句</p>
<p>continue 语句<br />
Python continue 语句跳出本次循环,而 break 跳出整个循环。<br />
continue 语句用来告诉 Python 跳过当前循环的剩余语句,然后继续进行下一轮循环。<br />
continue 语句用在 while 和 for 循环中。</p>
<p>pass 语句<br />
作用:是空函数,不做任何事情,用于暂时还未写逻辑和函数的里面</p>
<p>Python 日期和时间<br />
用函数方法<br />
time.time ( ) 来获取当前时间戳<br />
格式化时间<br />
<code>print(time.strftime(&quot;%Y-%m-%d %H:%M:%S&quot;, time.localtime()))</code></p>
]]></description>
</item>
<item>
<guid isPermalink="true">https://www.naraci.top/post/90e3f00.html</guid>
<title>Python爬取微博热搜至excel</title>
<link>https://www.naraci.top/post/90e3f00.html</link>
<category term="Python" scheme="https://www.naraci.top/categories/Python/" />
<category term="Python" scheme="https://www.naraci.top/tags/Python/" />
<pubDate>Fri, 14 Oct 2022 23:35:01 +0800</pubDate>
<description><![CDATA[ <h2 id="注意"><a class="anchor" href="#注意">#</a> 注意</h2>
<p>爬取热搜需要 cookie 和文件路径不然报错无法运行</p>
<figure class="highlight python"><figcaption data-lang="python"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token comment"># author:Naraci</span></pre></td></tr><tr><td data-num="2"></td><td><pre><span class="token comment"># time:2022/5/6 10:53</span></pre></td></tr><tr><td data-num="3"></td><td><pre><span class="token comment"># WX:Naraci</span></pre></td></tr><tr><td data-num="4"></td><td><pre><span class="token comment"># file: 微博热搜.py</span></pre></td></tr><tr><td data-num="5"></td><td><pre><span class="token comment"># IDE:PyCharm</span></pre></td></tr><tr><td data-num="6"></td><td><pre></pre></td></tr><tr><td data-num="7"></td><td><pre><span class="token keyword">import</span> requests</pre></td></tr><tr><td data-num="8"></td><td><pre><span class="token keyword">from</span> bs4 <span class="token keyword">import</span> BeautifulSoup</pre></td></tr><tr><td data-num="9"></td><td><pre><span class="token keyword">from</span> urllib <span class="token keyword">import</span> parse</pre></td></tr><tr><td data-num="10"></td><td><pre><span class="token keyword">import</span> xlwt</pre></td></tr><tr><td data-num="11"></td><td><pre></pre></td></tr><tr><td data-num="12"></td><td><pre>headers <span class="token operator">=</span> <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="13"></td><td><pre> <span class="token string">'user-agent'</span><span class="token punctuation">:</span> <span class="token string">'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36'</span></pre></td></tr><tr><td data-num="14"></td><td><pre> <span class="token string">' (KHTML, like Gecko) Chrome/101.0.4951.41 Mobile Safari/537.36 Edg/101.0.1210.32'</span><span class="token punctuation">,</span></pre></td></tr><tr><td data-num="15"></td><td><pre></pre></td></tr><tr><td data-num="16"></td><td><pre> <span class="token string">'cookie'</span><span class="token punctuation">:</span> <span class="token string">'填入cookie'</span></pre></td></tr><tr><td data-num="17"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="18"></td><td><pre></pre></td></tr><tr><td data-num="19"></td><td><pre></pre></td></tr><tr><td data-num="20"></td><td><pre><span class="token keyword">def</span> <span class="token function">Get_html</span><span class="token punctuation">(</span>url<span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token comment"># 获取页面</span></pre></td></tr><tr><td data-num="21"></td><td><pre> response <span class="token operator">=</span> requests<span class="token punctuation">.</span>get<span class="token punctuation">(</span>url<span class="token punctuation">,</span> headers<span class="token operator">=</span>headers<span class="token punctuation">)</span></pre></td></tr><tr><td data-num="22"></td><td><pre> <span class="token keyword">if</span> response<span class="token punctuation">.</span>status_code <span class="token operator">==</span> <span class="token number">200</span><span class="token punctuation">:</span></pre></td></tr><tr><td data-num="23"></td><td><pre> parse_html<span class="token punctuation">(</span>response<span class="token punctuation">.</span>text<span class="token punctuation">)</span></pre></td></tr><tr><td data-num="24"></td><td><pre> <span class="token keyword">else</span><span class="token punctuation">:</span></pre></td></tr><tr><td data-num="25"></td><td><pre> <span class="token keyword">print</span><span class="token punctuation">(</span>response<span class="token punctuation">.</span>status_code<span class="token punctuation">)</span></pre></td></tr><tr><td data-num="26"></td><td><pre> <span class="token keyword">pass</span></pre></td></tr><tr><td data-num="27"></td><td><pre></pre></td></tr><tr><td data-num="28"></td><td><pre></pre></td></tr><tr><td data-num="29"></td><td><pre><span class="token keyword">def</span> <span class="token function">parse_html</span><span class="token punctuation">(</span>content<span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token comment"># 解析页面</span></pre></td></tr><tr><td data-num="30"></td><td><pre> soup <span class="token operator">=</span> BeautifulSoup<span class="token punctuation">(</span>content<span class="token punctuation">,</span> <span class="token string">'lxml'</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="31"></td><td><pre> tds <span class="token operator">=</span> soup<span class="token punctuation">.</span>find_all<span class="token punctuation">(</span><span class="token string">'a'</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="32"></td><td><pre> datalist <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token comment"># 创建一个列表</span></pre></td></tr><tr><td data-num="33"></td><td><pre> <span class="token keyword">for</span> a <span class="token keyword">in</span> tds<span class="token punctuation">:</span></pre></td></tr><tr><td data-num="34"></td><td><pre> data <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span></pre></td></tr><tr><td data-num="35"></td><td><pre> title <span class="token operator">=</span> a<span class="token punctuation">.</span>get_text<span class="token punctuation">(</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="36"></td><td><pre> URL <span class="token operator">=</span> a<span class="token punctuation">[</span><span class="token string">'href'</span><span class="token punctuation">]</span></pre></td></tr><tr><td data-num="37"></td><td><pre> URL_whole <span class="token operator">=</span> parse<span class="token punctuation">.</span>urljoin<span class="token punctuation">(</span><span class="token string">'https://s.weibo.com/'</span><span class="token punctuation">,</span> URL<span class="token punctuation">)</span></pre></td></tr><tr><td data-num="38"></td><td><pre> <span class="token keyword">print</span><span class="token punctuation">(</span>title<span class="token punctuation">)</span></pre></td></tr><tr><td data-num="39"></td><td><pre> <span class="token keyword">print</span><span class="token punctuation">(</span>URL_whole<span class="token punctuation">)</span></pre></td></tr><tr><td data-num="40"></td><td><pre> <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"写入完成!!!!!"</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="41"></td><td><pre> data<span class="token punctuation">.</span>append<span class="token punctuation">(</span>title<span class="token punctuation">)</span> <span class="token comment"># 写入标题</span></pre></td></tr><tr><td data-num="42"></td><td><pre> data<span class="token punctuation">.</span>append<span class="token punctuation">(</span>URL_whole<span class="token punctuation">)</span> <span class="token comment"># 写入链接</span></pre></td></tr><tr><td data-num="43"></td><td><pre> datalist<span class="token punctuation">.</span>append<span class="token punctuation">(</span>data<span class="token punctuation">)</span></pre></td></tr><tr><td data-num="44"></td><td><pre> book <span class="token operator">=</span> xlwt<span class="token punctuation">.</span>Workbook<span class="token punctuation">(</span>encoding<span class="token operator">=</span><span class="token string">'utf-8'</span><span class="token punctuation">,</span> style_compression<span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">)</span> <span class="token comment"># 生成 excel 文件</span></pre></td></tr><tr><td data-num="45"></td><td><pre> sheet <span class="token operator">=</span> book<span class="token punctuation">.</span>add_sheet<span class="token punctuation">(</span><span class="token string">'微博热搜榜'</span><span class="token punctuation">,</span> cell_overwrite_ok<span class="token operator">=</span><span class="token boolean">True</span><span class="token punctuation">)</span> <span class="token comment"># 生成一个表单</span></pre></td></tr><tr><td data-num="46"></td><td><pre> cols <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token string">'标题'</span><span class="token punctuation">,</span> <span class="token string">'链接'</span><span class="token punctuation">]</span></pre></td></tr><tr><td data-num="47"></td><td><pre> <span class="token keyword">for</span> col <span class="token keyword">in</span> <span class="token builtin">range</span><span class="token punctuation">(</span><span class="token builtin">len</span><span class="token punctuation">(</span>cols<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">:</span></pre></td></tr><tr><td data-num="48"></td><td><pre> sheet<span class="token punctuation">.</span>write<span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> col<span class="token punctuation">,</span> cols<span class="token punctuation">[</span>col<span class="token punctuation">]</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="49"></td><td><pre> <span class="token keyword">for</span> i <span class="token keyword">in</span> <span class="token builtin">range</span><span class="token punctuation">(</span><span class="token builtin">len</span><span class="token punctuation">(</span>datalist<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">:</span></pre></td></tr><tr><td data-num="50"></td><td><pre> data <span class="token operator">=</span> datalist<span class="token punctuation">[</span>i<span class="token punctuation">]</span></pre></td></tr><tr><td data-num="51"></td><td><pre> <span class="token keyword">for</span> j <span class="token keyword">in</span> <span class="token builtin">range</span><span class="token punctuation">(</span><span class="token builtin">len</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">:</span></pre></td></tr><tr><td data-num="52"></td><td><pre> sheet<span class="token punctuation">.</span>write<span class="token punctuation">(</span>i <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">,</span> j<span class="token punctuation">,</span> data<span class="token punctuation">[</span>j<span class="token punctuation">]</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="53"></td><td><pre> book<span class="token punctuation">.</span>save<span class="token punctuation">(</span><span class="token string">"C:/路径/微博热搜榜.xls"</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="54"></td><td><pre></pre></td></tr><tr><td data-num="55"></td><td><pre></pre></td></tr><tr><td data-num="56"></td><td><pre><span class="token keyword">if</span> __name__ <span class="token operator">==</span> <span class="token string">'__main__'</span><span class="token punctuation">:</span></pre></td></tr><tr><td data-num="57"></td><td><pre> url <span class="token operator">=</span> <span class="token string">'https://s.weibo.com/top/summary'</span></pre></td></tr><tr><td data-num="58"></td><td><pre> Get_html<span class="token punctuation">(</span>url<span class="token punctuation">)</span></pre></td></tr></table></figure><p><img data-src="http://image.naraci.top/2022/05/10/7fb22be402cb7.png" alt=" " /></p>
]]></description>
</item>
<item>
<guid isPermalink="true">https://www.naraci.top/post/5753e137.html</guid>
<title>Cloudreve windows版安装成功后提示请求出现错误</title>
<link>https://www.naraci.top/post/5753e137.html</link>
<category term="Course" scheme="https://www.naraci.top/categories/Course/" />
<category term="Course" scheme="https://www.naraci.top/tags/Course/" />
<pubDate>Thu, 06 Oct 2022 23:35:01 +0800</pubDate>
<description><![CDATA[ <h3 id="前言"><a class="anchor" href="#前言">#</a> 前言</h3>
<p>今天根据官网安装手册搭建 Cloudreve 网盘程序后 IP 访问正常但是反代域名便出现主页提示 “请求时出现问题 xxx”<br />
<img data-src="https://forum.cloudreve.org/assets/files/2021-07-06/1625561821-684171-187f6530-f458-43ae-9d1d-ecb9048d22d1.png" alt="问题图片例子" /></p>
<h3 id="解决方法仅支持apache"><a class="anchor" href="#解决方法仅支持apache">#</a> 解决方法(仅支持 Apache)</h3>
<figure class="highlight markdown"><figcaption data-lang="markdown"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token title important"><span class="token punctuation">#</span>PROXY-START/</span></pre></td></tr><tr><td data-num="2"></td><td><pre><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>IfModule</span> <span class="token attr-name">mod_proxy.c</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="3"></td><td><pre>ProxyRequests Off</pre></td></tr><tr><td data-num="4"></td><td><pre>SSLProxyEngine on</pre></td></tr><tr><td data-num="5"></td><td><pre>AllowEncodedSlashes NoDecode</pre></td></tr><tr><td data-num="6"></td><td><pre>ProxyPass / http://127.0.0.1:5212/ nocanon</pre></td></tr><tr><td data-num="7"></td><td><pre>ProxyPassReverse / http://127.0.0.1:5212/</pre></td></tr><tr><td data-num="8"></td><td><pre><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>IfModule</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="9"></td><td><pre><span class="token title important"><span class="token punctuation">#</span>PROXY-END/</span></pre></td></tr></table></figure><p>在反代理修改配置文件添加下面代码即可!</p>
<p>注意:IP 地址记得也需修改为自己的 IP</p>
]]></description>
</item>
<item>
<guid isPermalink="true">https://www.naraci.top/post/21290.html</guid>
<title>数据库基础操作</title>
<link>https://www.naraci.top/post/21290.html</link>
<category term="MYSQL" scheme="https://www.naraci.top/categories/MYSQL/" />
<category term="MySQL" scheme="https://www.naraci.top/tags/MySQL/" />
<pubDate>Wed, 28 Sep 2022 23:35:01 +0800</pubDate>
<description><![CDATA[ <h1 id="创建新数据库"><a class="anchor" href="#创建新数据库">#</a> 创建新数据库</h1>
<figure class="highlight raw"><figcaption data-lang=""></figcaption><table><tr><td data-num="1"></td><td><pre>CREATE DATABASE &#39; 数据库名 &#39; CHARACTER SET (字符集)&#96;utf8mb4&#96; COLLATE (排序规则)&#96;utf8mb4_bin&#96;;</pre></td></tr></table></figure><h1 id="mysql创建新表"><a class="anchor" href="#mysql创建新表">#</a> Mysql 创建新表</h1>
<p><strong>创建数据表</strong></p>
<figure class="highlight raw"><figcaption data-lang=""></figcaption><table><tr><td data-num="1"></td><td><pre>CREATE TABLE &#96;数据库名称&#96;.&#96;数据表名称&#96;(</pre></td></tr><tr><td data-num="2"></td><td><pre>&#96;名&#96; varchar (255) NOT NULL (没有默认值), </pre></td></tr><tr><td data-num="3"></td><td><pre>);</pre></td></tr></table></figure><h1 id="mysql基础语法"><a class="anchor" href="#mysql基础语法">#</a> Mysql 基础语法</h1>
<ul>
<li>Insert 语句:向某一行插入一条数据。<br />
在查询编辑器中输入以下 sql.</li>
</ul>
<blockquote>
<p>INSERT INTO <code>user</code> <br />
( <code>mobile</code> , <code>name</code> , <code>sex</code> )<br />
VALUES<br />
('123',' 张三 ','1') // 这里不是反单引号!</p>
</blockquote>
<ul>
<li>Delete 删除语句:</li>
</ul>
<blockquote>
<p>DELETE FROM<br />
<code>表名</code> <br />
WHERE 值 = <code>表内对应值</code></p>
</blockquote>
<ul>
<li>Select 语句:</li>
</ul>
<blockquote>
<p>SELECT *<br />
<code>表名</code> <br />
FROM <code>表名</code> // 查询表内全部内容</p>
</blockquote>
<ul>
<li>Update 语句:</li>
</ul>
<blockquote>
<p>UPDATE <code>user</code> <br />
SET <code>name</code> = ’值‘<br />
WHERE mobile = ’值‘ // 根据 mobile 来确认修改数据的值</p>
</blockquote>
<h1 id="远程连接mysql数据库的一些问题"><a class="anchor" href="#远程连接mysql数据库的一些问题">#</a> 远程连接 MySQL 数据库的一些问题</h1>
<p>记录<strong>报错 2002(10060)</strong></p>
<ol>
<li>服务器安全组需要开放数据库的端口(默认 3306)。</li>
<li>假如使用宝塔面板则需要在安全内放行端口。</li>
<li>若上方内容还是不行则在服务器命令窗口输入关闭防火墙的命令。</li>
</ol>
]]></description>
</item>
<item>
<guid isPermalink="true">https://www.naraci.top/post/45655.html</guid>
<title>ccaa linux一键安装Arianna+AriaNg+FileBrowser</title>
<link>https://www.naraci.top/post/45655.html</link>
<category term="Bt" scheme="https://www.naraci.top/categories/Bt/" />
<category term="Bt" scheme="https://www.naraci.top/tags/Bt/" />
<pubDate>Tue, 27 Sep 2022 23:35:01 +0800</pubDate>
<description><![CDATA[ <h1 id="ccaa"><a class="anchor" href="#ccaa">#</a> CCAA</h1>
<p>原为 CentOS + Caddy + AriaNg + Aria2,故命名为 CCAA,不过现在不仅仅支持 CentOS,主流的 Debian、Ubuntu 也已经支持,自 2.0 版本已移除 Caddy,改用 Golang 写了一个简单的 webserver 来运行 AriaNg</p>
<ul>
<li>Aria2 提供离线下载</li>
<li>ccaa_web 支撑 AriaNg 运行</li>
<li>AriaNg 为 Aria2 提供 WEB 界面</li>
<li>Filemanager 提供文件管理</li>
</ul>
<hr />
<h1 id="主要功能"><a class="anchor" href="#主要功能">#</a> 主要功能</h1>
<ul>
<li>支持 HTTP/HTTPS/FTP/BT/ 磁力链接等离线下载,断点续传等</li>
<li>文件管理、视频在线播放</li>
<li>完善的帮助文档</li>
</ul>
<hr />
<h1 id="环境要求"><a class="anchor" href="#环境要求">#</a> 环境要求</h1>
<ul>
<li>支持的操作系统:CentOS 7-8、Debian 8-10、Ubuntu 16-18</li>
<li>操作系统要求 64 位</li>
</ul>
<hr />
<h1 id="安装ccaa"><a class="anchor" href="#安装ccaa">#</a> 安装 CCAA</h1>
<p>一键安装脚本(使用 root 用户):</p>
<figure class="highlight abap"><figcaption data-lang="ABAP"></figcaption><table><tr><td data-num="1"></td><td><pre>bash &lt;<span class="token punctuation">(</span>curl -Lsk https<span class="token punctuation">:</span>//raw<span class="token punctuation">.</span>githubusercontent<span class="token punctuation">.</span>com/helloxz/ccaa/master/ccaa<span class="token punctuation">.</span>sh<span class="token punctuation">)</span></pre></td></tr></table></figure><p>如果出现 - bash: curl: command not found 错误,说明 curl 命令没安装,请输入下面的命令先安装 curl,再回过头来执行上面的命令再来一次。</p>
<figure class="highlight abap"><figcaption data-lang="ABAP"></figcaption><table><tr><td data-num="1"></td><td><pre>#Debian <span class="token keyword">or</span> Ubuntu</pre></td></tr><tr><td data-num="2"></td><td><pre>apt<span class="token token-operator punctuation">-</span>get -y install curl</pre></td></tr><tr><td data-num="3"></td><td><pre>#CentOS</pre></td></tr><tr><td data-num="4"></td><td><pre>yum -y install curl</pre></td></tr></table></figure><hr />
<h1 id="常用命令"><a class="anchor" href="#常用命令">#</a> 常用命令</h1>
<ul>
<li>ccaa: 进入 CCAA 操作界面</li>
<li>ccaa status: 查看 CCAA 运行状态</li>
<li>ccaa stop: 停止 CCAA</li>
<li>ccaa start: 启动 CCAA</li>
<li>ccaa restart: 重启 CCAA</li>
<li>ccaa -v: 查看 CCAA 版本(2.0 开始支持)</li>
</ul>
<hr />
<h1 id="部分截图"><a class="anchor" href="#部分截图">#</a> 部分截图</h1>
<p><img data-src="https://i.imgtg.com/2022/10/06/phiXK.png" alt="截图" /><br />
<img data-src="https://i.imgtg.com/2022/10/06/ph1za.png" alt="截图" /></p>
<blockquote>
<p>文章转载于 https://gitee.com/hixz/ccaa/</p>
</blockquote>
]]></description>
</item>
<item>
<guid isPermalink="true">https://www.naraci.top/post/45550.html</guid>
<title>Photoshop制作太极</title>
<link>https://www.naraci.top/post/45550.html</link>
<category term="PS" scheme="https://www.naraci.top/tags/PS/" />
<pubDate>Sat, 24 Sep 2022 23:35:01 +0800</pubDate>
<description><![CDATA[ <h1 id="第一步-基础圆形的画法"><a class="anchor" href="#第一步-基础圆形的画法">#</a> 第一步 基础圆形的画法</h1>
<p>创建空白画布和复制图层</p>
<p>首先创建白色的画布(初始即可)即右下方复制一个画布,所有操作都在图层上面操作。<br />
<img data-src="https://i.imgtg.com/2022/09/22/gymNN.png" alt=" " /><br />
在最上面的选项栏 --&gt; 视图 --&gt; 打开标尺,并新建垂直和水平的参考线。<br />
<img data-src="https://i.imgtg.com/2022/09/22/gmMnv.png" alt="两条线居中" /><br />
在工具栏使用椭圆选框工具在十字交叉点按住 shift+alt 拖动鼠标左键画圆后按住 alt+del 建。<br />
<img data-src="https://i.imgtg.com/2022/09/22/gmyDC.png" alt="效果图" /></p>
<h1 id="第二步开始裁剪太极"><a class="anchor" href="#第二步开始裁剪太极">#</a> 第二步开始裁剪太极</h1>
<p>用矩形选框工具选中圆形的左半边 (从选中区减去,详情见下方示图)<br />
<img data-src="https://i.imgtg.com/2022/09/22/gmpxi.png" alt="鼠标移至图标上面会显示" /><br />
选中后可见圆形右边轮廓有清晰的虚线框即成功。<br />
再取两条水平参考线放置圆形的上面和下面相切。<br />
<img data-src="https://i.imgtg.com/2022/09/22/gm4Kj.png" alt="参考线与圆形相切" /></p>
<p>注意:矩形选框工具从左边白框顶部角端开始拖动并设为 (从选项区减去)</p>
<p>再次用椭圆选项框工具,在选项栏中选择 (添加选项区) 按下鼠标左键在圆形的四分之一处拖动绘制一个正圆,在圆的上半个区域。再选项栏选中 (从选项区减去) 同上原理在下方圆的四分之一处拖动正圆至圆的下半方出。如下图。<br />
<img data-src="https://i.imgtg.com/2022/09/22/gmVBG.png" alt="" /><br />
再次 ctrl+del 键取消一半黑色区域为白色。<br />
<img data-src="https://i.imgtg.com/2022/09/22/gmYZ1.png" alt="" /><br />
在太极一处画一个正圆。<br />
<img data-src="https://i.imgtg.com/2022/09/22/gmf0I.png" alt="" /><br />
ctrl+del 填充为白色后右击选择变换选区将中心点移至大圆的圆心再右击选择垂直翻转,按回车确认后 alt+del 填充为黑色。<br />
<img data-src="https://i.imgtg.com/2022/09/22/gm2H6.png" alt="完成效果图" /></p>
]]></description>
</item>
</channel>
</rss>