GO語言的進階之路-協程和Channel

                        GO語言的進階之路-協程和Channeljavascript

                                                做者:尹正傑css

版權聲明:原創做品,謝絕轉載!不然將追究法律責任。html

 

   看過我以前幾篇博客小夥伴可能對Golang語言的語法上了解的差很少了,可是,若是想要你的代碼和性能更高,那還得學點晉升的原本,這個時候咱們就須要引入Golang的協成這個概念了,其實,你可能早就據說了Golang的優點就是處理大併發,咱們能夠用它來作日誌收集系統,也能夠用它作業務上的「秒殺系統」,固然咱們還能夠用它來作「監控系統」。好了,下面跟我一塊兒來體會一下Golang的五味雜陳吧。java

 

一.什麼是協程;jquery

  再說協成以前,咱們須要瞭解兩個概念,即用戶態和內核態。git

1.什麼是用戶態;github

  官方解釋:用戶態(user mode)在計算機結構指兩項相似的概念。在CPU的設計中,用戶態指非特權狀態。在此狀態下,執行的代碼被硬件限定,不能進行某些操做,好比寫入其餘進程的存儲空間,以防止給操做系統帶來安全隱患。在操做系統的設計中,用戶態也相似,指非特權的執行狀態。內核禁止此狀態下的代碼進行潛在危險的操做,好比寫入系統配置文件、殺掉其餘用戶的進程、重啓系統等。api

   應用程序在用戶態下運行,僅僅只能執行cpu整個指令集的一個子集,該子集中不包含操做硬件功能的部分,所以,通常狀況下,在用戶態中有關I/O和內存保護(操做系統佔用的內存是受保護的,不能被別的程序佔用)。數組

  若是感興趣的朋友能夠參考:https://baike.baidu.com/item/%E7%94%A8%E6%88%B7%E6%80%81/9548791?fr=aladdin安全

 

2.什麼是內核態;

  內核態也叫和核心態。

  官方解釋:在處理器的存儲保護中,主要有兩種權限狀態,一種是核心態(管態),也被稱爲特權態;一種是用戶態(目態)。核心態是操做系統內核所運行的模式,運行在該模式的代碼,能夠無限制地對系統存儲、外部設備進行訪問。

  操做系統在內核態運行狀況下能夠訪問硬件上全部的內容。

  若是感興趣的朋友能夠參考:https://baike.baidu.com/item/%E6%A0%B8%E5%BF%83%E6%80%81/6845908?fr=aladdin

 

3.什麼是協成;

  官方解釋:一個程序能夠包含多個協程,能夠對比與一個進程包含多個線程,於是下面咱們來比較協程和線程。咱們知道多個線程相對獨立,有本身的上下文,切換受系統控制;而協程也相對獨立,有本身的上下文,可是其切換由本身控制,由當前協程切換到其餘協程由當前協程來控制。

  協程(coroutine)是Go語言中的輕量級線程實現,由Go運行時(runtime)管理。在一個函數調用前加上go關鍵字,此次調用就會在一個新的goroutine中併發執行。當被調用的函數返回時,這個goroutine也自動結束。須要注意的是,若是這個函數有返回值,那麼這個返回值會被丟棄。協成工做在用戶態,它相似於現場的運行方式能夠並行處理任務。

   若是感興趣的朋友能夠參考:http://baike.baidu.com/link?url=MKRg3Ca7Bokkqv5EarU1JO7Oz6Wn8jMhmJcoivDG27dOFeznk3gVDSl5SfN6P191GSwGDInEfDPVkQ6j3pJNbICpy04U0F1TkLOZHVzs1-u

 

二.建立一個協程;

   在一個函數調用前加上go關鍵字,此次調用就會在一個新的goroutine中併發執行,下面咱們一塊兒來看段代碼的執行結果:

 1 /*
 2 #!/usr/bin/env gorun
 3 @author :yinzhengjie
 4 Blog:http://www.cnblogs.com/yinzhengjie/tag/GO%E8%AF%AD%E8%A8%80%E7%9A%84%E8%BF%9B%E9%98%B6%E4%B9%8B%E8%B7%AF/
 5 EMAIL:y1053419035@qq.com
 6 */
 7 
 8 package main
 9 
10 import (
11 "time"
12 "fmt"
13 )
14 
15 func sayhi(s string)  {
16     for i := 0; i < 5; i++ {
17         time.Sleep(100*time.Millisecond)  //表示每次循環後都要休息100毫秒。
18         fmt.Println(s)
19     }
20 }
21 
22 func main() {
23     go sayhi("尹正傑")  //在函數執行前加個go,表示單獨起了一個協程,表示和當前主協程(main)並駕齊驅運行代碼。
24     sayhi("Golang")
25 }
26 
27 
28 #以上代碼執行結果以下:
29 Golang
30 尹正傑
31 尹正傑
32 Golang
33 Golang
34 尹正傑
35 尹正傑
36 Golang
37 Golang
38 尹正傑

   相信你們已經看到了一些端倪,咱們先定義了一個「sayhi」函數,這個函數的功能就是將傳入的字符串打印5遍,而後咱們在主程序上調用的時候,發如今函數面前加"go"關鍵字時,就會打印輸出,可是奇怪的是沒有按照順序打,它沒有先打印五遍「尹正傑」而後在打印5遍「Golang」,而是函數執行結果是不規律的打印了兩個字符串。這就是併發的效果,兩個函數同事運行效果。這也是咱們的併發之路的初體驗。哈哈~

 

 

三.協程的侷限性;

  發現讓兩端代碼同事運行貌似聽起來很高大上的樣子,可是有個侷限性,就是當主進程結束後,協成也會跟着結束,其實這個很好理解,咱們經過一段代碼就知道了:

 1 /*
 2 #!/usr/bin/env gorun
 3 @author :yinzhengjie
 4 Blog:http://www.cnblogs.com/yinzhengjie/tag/GO%E8%AF%AD%E8%A8%80%E7%9A%84%E8%BF%9B%E9%98%B6%E4%B9%8B%E8%B7%AF/
 5 EMAIL:y1053419035@qq.com
 6 */
 7 
 8 package main
 9 
10 import (
11     "time"
12     "fmt"
13 )
14 
15 func main() {
16     s := []int{2,7,1,6,4,3,11,15,17,5,8,9,12}
17     for _,n := range s{
18         go func(n int) { //定義一個匿名函數,並對該函數開啓協程,每次循環都會開啓一個協成,也就是說它開啓了13個協程。
19             time.Sleep(time.Duration(n) * time.Second) /*表示每循環一次就須要睡1s,睡的總時間是由n來控制的,
20             總長度是由s切片數組中最大的一個數字決定,也就是說這個協成最少須要17秒纔會結束喲*/
21             fmt.Println(n)
22         }(n)  //因爲這個函數是匿名函數,因此調用方式就直接:(n)調用,不用輸入函數名。
23     }
24     time.Sleep(12*time.Second) //主進程要執行的時間是12秒
25 }
26 
27 
28 
29 #以上代碼執行結果以下:
30 1
31 2
32 3
33 4
34 5
35 6
36 7
37 8
38 9
39 11
40 12

  是否是很神奇,直接就進行排序了,可是15和17沒有在終端輸出,爲何呢?這就是我所說的主進程結束,那麼整個程序也終將結束,由於主程序的時間只有12s,若是你想讓全部的數據都排序出來,就得把數字換成一個大於或等於17的,這樣纔會對全部的數字進行排序。由於協成13個協程都要執行完畢的話須要17s纔好使。

 

四.鎖;

1.爲何要引入鎖;

  在線上生活中,咱們爲了不多個用戶操做同一個文件,就會定義一個鎖,爲何咱們須要一個鎖呢?咱們能夠看如下的案例:

 1 package main
 2 
 3 import (
 4     "time"
 5     "fmt"
 6 )
 7 
 8 type Accout struct {
 9     money int
10 }
11 
12 func (a *Accout) Do_Prepare() {
13     time.Sleep(time.Second)
14 }
15 
16 func (a *Accout) Get_Gongzi(n int) {
17     a.money += n
18 }
19 
20 func (a *Accout) Give_Wife(n int) {
21     if a.money > n {
22         a.Do_Prepare()
23         a.money -= n
24     }
25 }
26 
27 func (a *Accout) Buy(n int) {
28     if a.money >n {
29         a.Do_Prepare()
30         a.money -= n
31     }
32 }
33 
34 func (a *Accout) Left()int {
35     return a.money
36 }
37 
38 func main() {
39     var   account Accout
40     account.Get_Gongzi(10000)
41     go account.Give_Wife(6000)
42     go account.Buy(5000)
43     time.Sleep(2 * time.Second) //不能讓主程序結束掉,由於主進程一結束go的協程也就跟着結束啦。
44     fmt.Println(account.Left())
45 }
46 
47 
48 
49 #以上代碼執行結果以下:
50 -1000

 

  估計你們都看出來端倪了,在讓兩個協程併發跑起來,發現你獲得的10000塊錢都讓給花出去了,是否是老尷尬了,寫的判斷語句也是沒有生效的,最終10000塊錢的工資,它居然花了11000,若是銀行這麼幹早就倒閉了,哈哈~那麼問題來了,若是解決這一種現象呢?目前有四種常見的處理方案即:互斥鎖,讀寫鎖和channel鎖以及waitgroup等等。

 

2.互斥鎖;

  互斥鎖是傳統的併發程序對共享資源進行訪問控制的主要手段。它由標準庫代碼包sync中的Mutex結構體類型表明。sync.Mutex類型(確切地說,是*sync.Mutex類型)只有兩個公開方法——Lock和Unlock。顧名思義,前者被用於鎖定當前的互斥量,然後者則被用來對當前的互斥量進行解鎖。

 1 /*
 2 #!/usr/bin/env gorun
 3 @author :yinzhengjie
 4 Blog:http://www.cnblogs.com/yinzhengjie/tag/GO%E8%AF%AD%E8%A8%80%E7%9A%84%E8%BF%9B%E9%98%B6%E4%B9%8B%E8%B7%AF/
 5 EMAIL:y1053419035@qq.com
 6 */
 7 
 8 package main
 9 
10 import (
11     "time"
12     "fmt"
13     "sync"
14 )
15 
16 
17 type Accout struct {
18     flag sync.Mutex
19     money int
20 }
21 
22 func (a *Accout) Do_Prepare() {
23     time.Sleep(time.Second)
24 }
25 
26 func (a *Accout) Get_Salary(n int) { //定義發的工資
27     a.money += n
28 }
29 
30 func (a *Accout) Give_Wife(n int) {  //上交給妻子的工資
31     a.flag.Lock()
32     defer a.flag.Unlock()
33     if a.money > n {
34         a.Do_Prepare()
35         a.money -= n
36     }else {
37         fmt.Println("您的餘額已不足!請及時充值~")
38     }
39 }
40 
41 func (a *Accout) Buy(n int) {  //本身買的工資
42     a.flag.Lock()
43     defer a.flag.Unlock()
44     if a.money >n {
45         a.Do_Prepare()
46         a.money -= n
47     }else {
48         fmt.Println("您的餘額已不足!請及時充值~")
49     }
50 }
51 
52 func (a *Accout) Left()int {
53     return a.money
54 }
55 
56 func main() {
57     var   account Accout
58     account.Get_Salary(10000)
59     go account.Give_Wife(6000)
60     go account.Buy(5000)
61     time.Sleep(2 * time.Second) //不能讓主程序結束掉,由於主進程一結束go的協程也就跟着結束啦。
62     fmt.Printf("您的剩餘工資是\033[31;1m%d\033[0m",account.Left())
63 
64 }
65 
66 
67 
68 #以上代碼解析以下:
69 您的餘額已不足!請及時充值~
70 您的剩餘工資是4000

 

 

3.讀寫鎖;

  在Go語言中,讀寫鎖由結構體類型sync.RWMutex表明。與互斥鎖相似,sync.RWMutex類型的零值就已是當即可用的讀寫鎖了。

  讀寫鎖便是針對於讀寫操做的互斥鎖。它與普通的互斥鎖最大的不一樣就是,它能夠分別針對讀操做和寫操做進行鎖定和解鎖操做。讀寫鎖控制下的多個寫操做之間都是互斥的,而且寫操做與讀操做之間也都是互斥的。可是,多個讀操做之間卻不存在互斥關係。

 

A.多個讀操做之間卻不存在互斥關係;

  咱們會發現讀取操做沒有存在互斥的關係。5個進程同事進行讀取,最終都順利並行跑完了。

 1 /*
 2 #!/usr/bin/env gorun
 3 @author :yinzhengjie
 4 Blog:http://www.cnblogs.com/yinzhengjie/tag/GO%E8%AF%AD%E8%A8%80%E7%9A%84%E8%BF%9B%E9%98%B6%E4%B9%8B%E8%B7%AF/
 5 EMAIL:y1053419035@qq.com
 6 */
 7 
 8 package main
 9 
10 import (
11     "sync"
12     "time"
13 )
14 
15 var m *sync.RWMutex  //定義m的類型爲讀寫鎖。
16 
17 func main() {
18     m = new(sync.RWMutex)
19     go read("第一次讀取:")  //開啓5個協程進行讀取操做。若是不能併發跑最少須要5秒鐘時間。
20     go read("第二次讀取:")
21     go read("第三次讀取:")
22     go read("第四次讀取:")
23     go read("第五次讀取:")
24     time.Sleep(2* time.Second)  //主進程只有2s,意味着這個程序最多能運行2s的時間。
25 }
26 
27 func read(i string) {
28     println(i, "read start")
29     m.RLock()  //讀鎖定
30     println(i, "資料正在讀取中....")
31     time.Sleep(1 * time.Second)  //改函數執行完畢最少須要睡1秒。
32     m.RUnlock() //讀解鎖
33     println(i, "read end")
34 }
35 
36 
37 
38 #以上代碼執行結果以下:
39 第二次讀取: read start
40 第二次讀取: 資料正在讀取中....
41 第一次讀取: read start
42 第一次讀取: 資料正在讀取中....
43 第三次讀取: read start
44 第三次讀取: 資料正在讀取中....
45 第四次讀取: read start
46 第四次讀取: 資料正在讀取中....
47 第五次讀取: read start
48 第五次讀取: 資料正在讀取中....
49 第一次讀取: read end
50 第三次讀取: read end
51 第二次讀取: read end
52 第四次讀取: read end
53 第五次讀取: read end

 

 

B.讀寫鎖控制下的多個寫操做之間都是互斥的,而且寫操做與讀操做之間也都是互斥的;

  咱們發現,讀的時候不能寫,寫的時候不能讀,咱們將主程序設置的時間是10秒鐘,一次讀兩次寫花費的總時間是12秒鐘,所以確定有一個是沒法完成度或是寫的部分。

 1 /*
 2 #!/usr/bin/env gorun
 3 @author :yinzhengjie
 4 Blog:http://www.cnblogs.com/yinzhengjie/tag/GO%E8%AF%AD%E8%A8%80%E7%9A%84%E8%BF%9B%E9%98%B6%E4%B9%8B%E8%B7%AF/
 5 EMAIL:y1053419035@qq.com
 6 */
 7 
 8 package main
 9 
10 import (
11     "sync"
12     "time"
13 )
14 
15 var m *sync.RWMutex
16 
17 func read(i string) {
18     println(i, "read start")
19     m.RLock()
20     println(i, "資料正在讀取中.....")
21     time.Sleep(4 * time.Second)
22     m.RUnlock()
23     println(i, "read end")
24 }
25 
26 func write(i string) {
27     println(i, "write start")
28     m.Lock() //寫操做鎖定
29     println(i, "數據正在寫入硬盤中.....")
30     time.Sleep(4 * time.Second)
31     m.Unlock()  //寫操做解鎖
32     println(i, "write end")
33 }
34 
35 func main(){
36     m = new(sync.RWMutex)
37     go write("第一次寫入") //寫的時候啥都不能幹,即其餘協程沒法寫入,也沒法讀取。
38     go read("第一次讀取")
39     go write("第二次寫入")
40     time.Sleep(10 * time.Second) //主進程只給出10秒的時間,可是整個進程跑完最少須要12秒的時間。
41 }
42 
43 
44 
45 
46 #以上代碼直接結果以下:
47 第一次寫入 write start
48 第一次寫入 數據正在寫入硬盤中.....
49 第一次讀取 read start
50 第二次寫入 write start
51 第一次寫入 write end
52 第一次讀取 資料正在讀取中.....
53 第一次讀取 read end
54 第二次寫入 數據正在寫入硬盤中.....

 

4.channel鎖;

  channel鎖的工做原理就是讓2個協成互相通訊,一會咱們會詳細介紹。

 1 /*
 2 #!/usr/bin/env gorun
 3 @author :yinzhengjie
 4 Blog:http://www.cnblogs.com/yinzhengjie/tag/GO%E8%AF%AD%E8%A8%80%E7%9A%84%E8%BF%9B%E9%98%B6%E4%B9%8B%E8%B7%AF/
 5 EMAIL:y1053419035@qq.com
 6 */
 7 
 8 package main
 9 
10 import (
11     "time"
12     "fmt"
13     "sync"
14 )
15 
16 
17 type Accout struct {
18     flag sync.Mutex
19     money int
20 }
21 
22 func (a *Accout) Do_Prepare() {
23     time.Sleep(time.Second)
24 }
25 
26 func (a *Accout) Get_Gongzi(n int) {
27     a.money += n
28 }
29 
30 func (a *Accout) Give_Wife(n int) {
31     a.flag.Lock()
32     defer a.flag.Unlock()
33     if a.money > n {
34         a.Do_Prepare()
35         a.money -= n
36     }else {
37         fmt.Println("您的餘額已不足,請及時充值!")
38     }
39 }
40 
41 func (a *Accout) Buy(n int) {
42     a.flag.Lock()
43     defer a.flag.Unlock()
44     if a.money >n {
45         a.Do_Prepare()
46         a.money -= n
47     }else {
48         fmt.Println("您的餘額已不足,請及時充值!")
49     }
50 }
51 
52 func (a *Accout) Left()int {
53     return a.money
54 }
55 
56 func main() {
57     var   account Accout
58     account.Get_Gongzi(10000)
59 
60     var work_info  chan string
61     work_info = make(chan string ,2)  //定義一個channel
62 
63     go func() {
64         account.Give_Wife(6000)
65         work_info <- "I done"  //若是該進程執行完畢就發送一條數據給channel,下面的那個也同樣
66     }()
67 
68     go func() {
69         account.Buy(50000)
70         work_info <- "I  have done too!"
71     }()
72 
73     cnt := 0
74     for i := range work_info {
75         fmt.Println(i)
76         cnt++ //每次循環都疊加1,當2個協程都工做完就讓主程序結束。
77         if cnt >= 2 {
78             break
79         }
80 
81     }
82     defer close(work_info)
83     fmt.Printf("您的剩餘工資是\033[31;1m%d\033[0m",account.Left())
84 }
85 
86 
87 
88 
89 #以上代碼直接結果以下:
90 您的餘額已不足,請及時充值!
91 I  have done too!
92 I done
93 您的剩餘工資是4000

 

  其實channel還有一個好處就是解決超時問題,就是若是在規定的時間沒有完成進程的內容,咱們就返回給用戶超時的狀態。如下是示例代碼:

 1 /*
 2 #!/usr/bin/env gorun
 3 @author :yinzhengjie
 4 Blog:http://www.cnblogs.com/yinzhengjie/tag/GO%E8%AF%AD%E8%A8%80%E7%9A%84%E8%BF%9B%E9%98%B6%E4%B9%8B%E8%B7%AF/
 5 EMAIL:y1053419035@qq.com
 6 */
 7 
 8 package main
 9 
10 import (
11     "time"
12     "fmt"
13     "sync"
14 )
15 
16 
17 type Accout struct {
18     flag sync.Mutex
19     money int
20 }
21 
22 func (a *Accout) Do_Prepare() {
23     time.Sleep(time.Second)
24 }
25 
26 func (a *Accout) Get_Gongzi(n int) {
27     a.money += n
28 }
29 
30 func (a *Accout) Give_Wife(n int) {
31     a.flag.Lock()
32     defer a.flag.Unlock()
33     if a.money > n {
34         a.Do_Prepare()
35         a.money -= n
36     }else {
37         fmt.Println("您的餘額已不足,請及時充值!")
38     }
39 }
40 
41 func (a *Accout) Buy(n int) {
42     a.flag.Lock()
43     defer a.flag.Unlock()
44     if a.money >n {
45         a.Do_Prepare()
46         a.money -= n
47     }else {
48         fmt.Println("您的餘額已不足,請及時充值!")
49     }
50 }
51 
52 func (a *Accout) Left()int {
53     return a.money
54 }
55 
56 func main() {
57     var   account Accout
58     account.Get_Gongzi(10000)
59 
60     var work_info  chan string
61     work_info = make(chan string ,2)  //定義一個channel
62 
63     go func() {
64         account.Give_Wife(6000)
65         work_info <- "I done"  //若是該進程執行完畢就發送一條數據給channel,下面的那個也同樣
66     }()
67 
68     go func() {
69         account.Buy(50000)
70         work_info <- "I  have done too!"
71     }()
72 
73     cnt := 0
74     for i := range work_info {
75         fmt.Println(i)
76         cnt++ //每次循環都疊加1,當2個協程都工做完就讓主程序結束。
77         if cnt >= 2 {
78             fmt.Println("操做超時")
79             return
80         }
81 
82     }
83     defer close(work_info)
84     fmt.Printf("您的剩餘工資是\033[31;1m%d\033[0m",account.Left())
85 }
86 
87 
88 
89 #以上代碼執行結果以下:
90 您的餘額已不足,請及時充值!
91 I  have done too!
92 I done
93 操做超時

 

5.waitgroup進行同步;

  WaitGroup在go語言中,用於線程同步,它可以一直等到全部的goroutine執行完成,而且阻塞主線程的執行,直到全部的goroutine執行完成。

 1 /*
 2 #!/usr/bin/env gorun
 3 @author :yinzhengjie
 4 Blog:http://www.cnblogs.com/yinzhengjie/tag/GO%E8%AF%AD%E8%A8%80%E7%9A%84%E8%BF%9B%E9%98%B6%E4%B9%8B%E8%B7%AF/
 5 EMAIL:y1053419035@qq.com
 6 */
 7 
 8 package main
 9 
10 import (
11     "time"
12     "fmt"
13     "sync"
14 )
15 
16 type Accout struct {
17     flag sync.Mutex
18     money int
19 }
20 
21 func (a *Accout) Do_Prepare() {
22     time.Sleep(time.Second)
23 }
24 
25 func (a *Accout) Get_Gongzi(n int) {
26     a.money += n
27 }
28 
29 func (a *Accout) Give_Wife(n int) {
30     a.flag.Lock()
31     defer a.flag.Unlock()
32     if a.money > n {
33         a.Do_Prepare()
34         a.money -= n
35     }else {
36         fmt.Println("您的餘額已不足,請及時充值!")
37     }
38 }
39 
40 func (a *Accout) Buy(n int) {
41     a.flag.Lock()
42     defer a.flag.Unlock()
43     if a.money >n {
44         a.Do_Prepare()
45         a.money -= n
46     }else {
47         fmt.Println("您的餘額已不足,請及時充值!")
48     }
49 }
50 
51 func (a *Accout) Left()int {
52     return a.money
53 }
54 
55 func main() {
56     var   account Accout
57     account.Get_Gongzi(10000)
58     wg := new(sync.WaitGroup) //定義一個WaitGroup,就是用來等待都
59     wg.Add(2) //有幾個進程須要等待就寫幾個,寫多或寫少都會報錯喲~
60     go func() {
61         account.Give_Wife(6000)
62         wg.Done() //該進程結束就發送結束標誌。
63     }()
64     go func() {
65         account.Buy(5000)
66         wg.Done()
67     }()
68     wg.Wait()  //等待全部協程結束後在執行如下都代碼。
69     fmt.Printf("您的剩餘工資是\033[31;1m%d\033[0m",account.Left())
70 }
71 
72 
73 
74 #以上代碼執行結果以下:
75 您的餘額已不足,請及時充值!
76 您的剩餘工資是5000 

 

五.協程池;

  協程池能夠控制並行度,複用協程。

 1 /*
 2 #!/usr/bin/env gorun
 3 @author :yinzhengjie
 4 Blog:http://www.cnblogs.com/yinzhengjie/tag/GO%E8%AF%AD%E8%A8%80%E7%9A%84%E8%BF%9B%E9%98%B6%E4%B9%8B%E8%B7%AF/
 5 EMAIL:y1053419035@qq.com
 6 */
 7 
 8 package main
 9 
10 import (
11     "sync"
12     "net/http"
13     "log"
14 )
15 
16 func work(ch chan string, wg *sync.WaitGroup) { //ch是用來接受數據,wg是用來同步協程的.
17     for u := range ch{
18         resp,err := http.Get(u) //將channel中的數據讀取出來
19         if err != nil {
20             log.Print(err)
21             return
22         }
23         log.Printf("訪問的網站是:%s,網頁的大小是:%v",u,resp.ContentLength)
24         resp.Body.Close() //
25     }
26     wg.Done()
27 }
28 
29 func main() {
30     wg := new(sync.WaitGroup) //定義WaitGroup爲了進行協程同步。
31     wg.Add(5) //開啓5個協程池。
32     taskch := make(chan string) //建立一個channel
33     for i := 0; i < 5; i++ {
34         go work(taskch,wg)
35     }
36     urls := []string{"http://www.baidu.com","http://www.zhihu.com","http://www.cnblogs.com/yinzhengjie/p/7201980.html"} //定義須要訪問的網站。
37         for _,url := range urls{
38         taskch <- url //往channel發送數據。
39         }
40         close(taskch)
41         wg.Wait() //等待程序結束
42 }
43 
44 
45 
46 #以上代碼執行結果以下:
47 2017/07/24 15:23:02 訪問的網站是:http://www.baidu.com,網頁的大小是:-1
48 2017/07/24 15:23:03 訪問的網站是:http://www.cnblogs.com/yinzhengjie/p/7201980.html,網頁的大小是:-1
49 2017/07/24 15:23:03 訪問的網站是:http://www.zhihu.com,網頁的大小是:-1

 

六.channel的引入;

  Go 語言中的 channel 是實現  goroutine 間無鎖通訊的關鍵機制,他使得寫多線程併發程序變得簡單、靈活、觸手可得。channel是Go語言在語言級別提供的goroutine間的通訊方式,咱們可使用channel在多個goroutine之間傳遞消息。channel是進程內的通訊方式,所以經過channel傳遞對象的過程和調用函數時的參數傳遞行爲比較一致,好比也能夠傳遞指針等。

 

1.實現channel的Receive與Sender;

  初學者能夠理解成:channel實際上就是接受和發送數據。channel是類型相關的,一個channel只能傳遞一種類型的值,這個類型須要在聲明channel時指定。有了這些就夠了,咱們一塊兒來看段代碼來感覺下channel吧。

 1 /*
 2 #!/usr/bin/env gorun
 3 @author :yinzhengjie
 4 Blog:http://www.cnblogs.com/yinzhengjie/tag/GO%E8%AF%AD%E8%A8%80%E7%9A%84%E8%BF%9B%E9%98%B6%E4%B9%8B%E8%B7%AF/
 5 EMAIL:y1053419035@qq.com
 6 */
 7 
 8 package main
 9 
10 import "fmt"
11 
12 
13 
14 func sum(s []int, c chan int) {  //該函數是對切片數組求和,須要傳入一個切片數組和一個channel。
15     sum := 0
16     for _,v := range s {
17         sum += v //表示對切片數組進行求和。
18     }
19     c <- sum   //將sum的數據送給名稱爲c的channel,也就是說將數組中的數字的值傳給channel。給channle賦值的時候,其應該在左邊。
20 }
21 
22 func main() {
23     Slice_array := []int{1,2,3,4,-9,4,2,0}
24     channel_name := make(chan int)  //用chan定義一個channel對象名稱爲channel_name,其類型是int。
25     go sum(Slice_array[:len(Slice_array)/2],channel_name)  //在函數上開啓協成,注意格式。是在函數前面加個go參數便可。
26     go sum(Slice_array[len(Slice_array)/2:],channel_name)
27     x,y := <-channel_name, <-channel_name  //將channel_name中的數據接收並複製給x和y,固然你也能夠定義兩個變量名不一樣的channle,要注意到是取channel的值時,其應該在右邊,
28     fmt.Println(x,y,x+y)
29 }
30 
31 
32 
33 #以上代碼執行結果以下:
34 -3 10 7

 

2.channel的緩衝大小;

 1 /*
 2 #!/usr/bin/env gorun
 3 @author :yinzhengjie
 4 Blog:http://www.cnblogs.com/yinzhengjie/tag/GO%E8%AF%AD%E8%A8%80%E7%9A%84%E8%BF%9B%E9%98%B6%E4%B9%8B%E8%B7%AF/
 5 EMAIL:y1053419035@qq.com
 6 */
 7 
 8 package main
 9 
10 import "fmt"
11 
12 
13 
14 func main() {
15     ch := make(chan int,5)  /*定義緩衝大小容量爲5。下面給channel發送了3個值,若是接受當值超過預約義的5時,就會
16      報錯喲!若是你不寫的化就會報錯:"fatal error: all goroutines are asleep - deadlock!"*/
17     ch <- 100
18     ch <- 200
19     ch <- 300
20     fmt.Println(<-ch)  //第一次取值
21     fmt.Println(<-ch)  //第二次取值
22     fmt.Println(<-ch)  //第三次取值
23 }
24 
25 
26 
27 #以上代碼執行結果以下:
28 100
29 200
30 300

 

3.channel的應用;

 1 /*
 2 #!/usr/bin/env gorun
 3 @author :yinzhengjie
 4 Blog:http://www.cnblogs.com/yinzhengjie/tag/GO%E8%AF%AD%E8%A8%80%E7%9A%84%E8%BF%9B%E9%98%B6%E4%B9%8B%E8%B7%AF/
 5 EMAIL:y1053419035@qq.com
 6 */
 7 
 8 package main
 9 
10 import "fmt"
11 
12 func fibonacci(n int,c chan int) { //定義斐波拉契數列函數。
13     x,y := 0,1
14     for i := 0; i < n; i++ { 
15         c <- x
16         x,y = y,x+y
17         if x > 100 {  //表示當循環到兩個數字之和大於100時就終止循環。
18             break
19         }
20     }
21     close(c) //關閉channel,若是不關閉就會被鎖,出現報錯:"deadlock!"
22 }
23 
24 func main() {
25     channel_name := make(chan int,15) //定義channel緩衝大小時爲15,表示最多存取15個元素。
26     go fibonacci(cap(channel_name),channel_name)
27     for i := range channel_name{  //遍歷channel_name
28         fmt.Println(i)
29     }
30 }
31 
32 
33 
34 #以上代碼執行結果以下:
35 0
36 1
37 1
38 2
39 3
40 5
41 8
42 13
43 21
44 34
45 55
46 89

 

 4.Channeld的select語法;

 1 /*
 2 #!/usr/bin/env gorun
 3 @author :yinzhengjie
 4 Blog:http://www.cnblogs.com/yinzhengjie/tag/GO%E8%AF%AD%E8%A8%80%E7%9A%84%E8%BF%9B%E9%98%B6%E4%B9%8B%E8%B7%AF/
 5 EMAIL:y1053419035@qq.com
 6 */
 7 
 8 package main
 9 
10 import "fmt"
11 
12 func fibonacci(channel_name,quit chan int)  { //定義兩個channle對象channel_name和quit。
13     x,y := 0,1
14     for{
15         select {
16         case channel_name <- x:  //用channel_name接受數據。
17             x,y = y,x+y
18 
19         case <-quit:  //表示當接收到quit的channel時,就執行如下代碼。其實就是實現關閉channel的功能。
20             fmt.Println("EXIT")
21             return //函數一退出協程也就跟着退出了
22         }
23     }
24 }
25 
26 func main() {
27     channel_name := make(chan int)
28     quit := make(chan int)
29     go func() {
30         for i := 0; i < 11; i++ {
31             fmt.Println(<-channel_name)  //"<-channel_name"表示讀取channel_name中的參數。
32         }
33         quit<- 100 /*當for循環結束後,咱們隨便給quit的channel傳一個值就能夠實現退出函數的功能。咱們以前須要
34         用close(c)來退出發信號的功能,主動權在"fibonacci",而咱們如今咱們用quit來主動退出協程。*/
35     }() //這裏加個括號是在調用當前函數。
36     fibonacci(channel_name,quit)  //將channel_name和quit傳遞給fibonacci函數
37 }
38 
39 
40 
41 #以上代碼珍惜結果以下:
42 0
43 1
44 1
45 2
46 3
47 5
48 8
49 13
50 21
51 34
52 55
53 EXIT

 

 5.default語法;

 1 /*
 2 #!/usr/bin/env gorun
 3 @author :yinzhengjie
 4 Blog:http://www.cnblogs.com/yinzhengjie/tag/GO%E8%AF%AD%E8%A8%80%E7%9A%84%E8%BF%9B%E9%98%B6%E4%B9%8B%E8%B7%AF/
 5 EMAIL:y1053419035@qq.com
 6 */
 7 
 8 package main
 9 
10 import (
11     "time"
12     "fmt"
13 )
14 
15 func main() {
16     tick := time.Tick(1000*time.Millisecond) //也能夠這樣寫:「tick := time.NewTicker(1000*time.Millisecond).C」其中這個點C就是一個channel。
17     boom := time.After(5000*time.Millisecond)
18     for  {
19         select {
20         case <-tick:
21             fmt.Println("滴答。。。")
22         case <-boom:
23             fmt.Println("砰~")
24             return
25         default:
26             fmt.Println("吃一口涼皮")
27             time.Sleep(500*time.Millisecond)
28         }
29     }
30 }
31 
32 
33 
34 #以上代碼執行結果以下:
35 吃一口涼皮
36 吃一口涼皮
37 滴答。。。
38 吃一口涼皮
39 吃一口涼皮
40 滴答。。。
41 吃一口涼皮
42 吃一口涼皮
43 滴答。。。
44 吃一口涼皮
45 吃一口涼皮
46 滴答。。。
47 吃一口涼皮
48 吃一口涼皮
49 砰~

 

 6.channel擴展;

A.time.NewTicker用法展現:

  當咱們在寫一個監控系統的時候,須要實施監控,可是定義巡檢時間的話,須要咱們自定義巡檢週期性。這個時候咱們就能夠用到一個叫時間設置器的函數,即:time.NewTicker。

 1 /*
 2 #!/usr/bin/env gorun
 3 @author :yinzhengjie
 4 Blog:http://www.cnblogs.com/yinzhengjie/tag/GO%E8%AF%AD%E8%A8%80%E7%9A%84%E8%BF%9B%E9%98%B6%E4%B9%8B%E8%B7%AF/
 5 EMAIL:y1053419035@qq.com
 6 */
 7 
 8 package main
 9 
10 import (
11     "time"
12     "fmt"
13 )
14 
15 func main() {
16     timer := time.NewTicker(3 * time.Second)  //設置定時器,定義timer的基本單位是三秒。
17     cnt := 0
18     for _ = range timer.C{  //其中timer.C就是一個channel
19         cnt++
20         if cnt > 3 {
21             timer.Stop()  //調用方式
22             return //這裏是手動停下來,通常是不會讓他停下來,好比在監控的時候,可是有結束條件的時候用return的話是不會報錯的
23         }
24         fmt.Println("yinzhengjie")
25     }
26 }
27 
28 
29 
30 #以上代碼執行結果以下:
31 
32 yinzhengjie
33 yinzhengjie
34 yinzhengjie

 

B.time.After用法展現:

  要注意的是,「time.NewTicker」須要調用"Stop"方法纔會被執行,而「time.After」調用的姿式也不同,咱們一塊兒來體驗一下吧。

 1 /*
 2 #!/usr/bin/env gorun
 3 @author :yinzhengjie
 4 Blog:http://www.cnblogs.com/yinzhengjie/tag/GO%E8%AF%AD%E8%A8%80%E7%9A%84%E8%BF%9B%E9%98%B6%E4%B9%8B%E8%B7%AF/
 5 EMAIL:y1053419035@qq.com
 6 */
 7 
 8 package main
 9 
10 import (
11     "time"
12     "fmt"
13 )
14 
15 func main() {
16     c := time.After(time.Second*3)  //表示讓其睡眠3秒鐘。
17     <-c   //調用方式
18     fmt.Println("主進程執行完畢")
19 }
20 
21 
22 
23 #以上代碼執行結果以下:
24 主進程執行完畢

 

C.channel的深刻淺出;

 1 /*
 2 #!/usr/bin/env gorun
 3 @author :yinzhengjie
 4 Blog:http://www.cnblogs.com/yinzhengjie/tag/GO%E8%AF%AD%E8%A8%80%E7%9A%84%E8%BF%9B%E9%98%B6%E4%B9%8B%E8%B7%AF/
 5 EMAIL:y1053419035@qq.com
 6 */
 7 
 8 package main
 9 
10 import (
11     "net/http"
12     "log"
13     "fmt"
14     "time"
15 )
16 
17 /*
18 1.channel就好像一個傳送帶,能夠源源不斷的往裏面放數據,只要不close就能夠永遠發送數據。
19 2.若是channel裏面沒有數據,接收方會阻塞。
20 3.若是沒有人正在等待channel的數據,發送方會阻塞。
21 4.從一個close的channel取數據永遠不會阻塞,同時獲取的是默認值
22 */
23 
24 
25 func Print_url(url string) {
26     res,err := http.Get(url)
27     if err != nil {
28         log.Fatal("11111",err)
29     }
30     defer res.Body.Close()
31     fmt.Printf("網頁的狀態返回碼是:%v\n",res.Status)
32 
33 }
34 
35 func work(resave chan string) {
36 
37     for  {
38         url,ok := <- resave   //若是channel裏面沒有數據,接收方會阻塞。用url,ok兩個參數來接受channel,能夠從channel會返回兩個參數。url表示接受的數據。ok接受的信息是channel是否結束。
39         //fmt.Println(url,ok)
40         if !ok { //判斷channel是否關閉。
41             break
42         }
43         Print_url(url)
44     }
45 
46     //for i := range resave { //range語法一值在接受數據,而channel能夠源源不斷的往裏面添加數據。從一個close的channel取數據永遠不會阻塞,同時獲取的是默認值。
47     //    Print_url(i)
48     //}
49 }
50 
51 func main() {
52     make_string := make(chan string)
53     for i := 0;i<3 ;i++  {
54         go work(make_string)
55     }
56     urls := []string{"http://www.baidu.com","http://www.qq.com","http://www.weixin.com"}
57         for _,i := range urls    {
58         make_string <- i //若是沒有人正在等待channel的數據,發送方會阻塞。
59         }
60         close(make_string) //channel就好像一個傳送帶,能夠源源不斷的往裏面放數據,只要不close就能夠永遠發送數據。
61         time.Sleep(5 * time.Second)
62     }
63 
64 
65 
66 
67 #以上代碼輸出結果以下:
68 網頁的狀態返回碼是:200 OK
69 網頁的狀態返回碼是:200 OK
70 網頁的狀態返回碼是:200 OK

 

D.waitgroup+channel配合使用;

  咱們能夠對C進行優化,在實際生產環境中,咱們最好不要用"time.sleep"這個方法來實現主程序等待子程序執行完畢,由於會出現異響不到的bug喲~推薦是用waitgrout來取代這個sleep時間。

 1 package main
 2 
 3 import (
 4     "net/http"
 5     "log"
 6     "fmt"
 7     //"time"
 8     "sync"
 9 )
10 
11 /*
12 1.channel就好像一個傳送帶,能夠源源不斷的往裏面放數據,只要不close就能夠永遠發送數據。
13 2.若是channel裏面沒有數據,接收方會阻塞。
14 3.若是沒有人正在等待channel的數據,發送方會阻塞。
15 4.從一個close的channel取數據永遠不會阻塞,同時獲取的是默認值
16 */
17 
18 
19 func Print_url(url string) {
20     res,err := http.Get(url)
21     if err != nil {
22         log.Fatal("11111",err)
23     }
24     defer res.Body.Close()
25     fmt.Printf("網頁的狀態返回碼是:%v\n",res.Status)
26 
27 }
28 
29 func work(resave chan string,wg *sync.WaitGroup) {
30 
31     for  {
32         url,ok := <- resave   //若是channel裏面沒有數據,接收方會阻塞。用url,ok兩個參數來接受channel,能夠從channel會返回兩個參數。url表示接受的數據。ok接受的信息是channel是否結束。
33         //fmt.Println(url,ok)
34         if !ok { //判斷channel是否關閉。
35             break
36         }
37         Print_url(url)
38     }
39 
40     //for i := range resave { //range語法一值在接受數據,而channel能夠源源不斷的往裏面添加數據。從一個close的channel取數據永遠不會阻塞,同時獲取的是默認值。
41     //    Print_url(i)
42     //}
43     wg.Done()
44 }
45 
46 func main() {
47     wg := new(sync.WaitGroup)
48     //var num = 3
49     //make_string := make(chan string)
50     //for i := 0;i<num ;i++  {
51     //    go work(make_string,wg)
52     //}
53     //wg.Add(num)
54 
55     make_string := make(chan string)
56     for i := 0;i<3 ;i++  {
57         wg.Add(1)  //啓用的協程數和add的進程池保持一致。
58         go work(make_string,wg)
59     }
60 
61     urls := []string{"http://www.baidu.com","http://www.qq.com","http://www.weixin.com"}
62         for _,i := range urls    {
63         make_string <- i //若是沒有人正在等待channel的數據,發送方會阻塞。
64         }
65         close(make_string) //channel就好像一個傳送帶,能夠源源不斷的往裏面放數據,只要不close就能夠永遠發送數據。
66         //time.Sleep(5 * time.Second)
67         wg.Wait() //等待
68     }
69 
70 
71 
72 #以上代碼執行結果以下:
73 網頁的狀態返回碼是:200 OK
74 網頁的狀態返回碼是:200 OK
75 網頁的狀態返回碼是:200 OK

 

七.爬蟲進階之路;

  在咱們想要寫出來一個爬蟲出來,咱們首先得了解幾個模塊,知道它的用法,這樣咱們才能寫出一個真正的爬蟲,接下來跟我一塊兒看看經常使用的幾個模塊吧。

1."net/http"模塊用法展現;

  "net/http"模塊可用於爬去url的內容。

 1 /*
 2 #!/usr/bin/env gorun
 3 @author :yinzhengjie
 4 Blog:http://www.cnblogs.com/yinzhengjie/tag/GO%E8%AF%AD%E8%A8%80%E7%9A%84%E8%BF%9B%E9%98%B6%E4%B9%8B%E8%B7%AF/
 5 EMAIL:y1053419035@qq.com
 6 */
 7 
 8 package main
 9 
10 import (
11     "net/http"
12     "log"
13     "io"
14     "os"
15 )
16 
17 func main() {
18     url := "http://www.xiaohuar.com"  //定義一個URl,也就是咱們要爬的網站。
19     resp,err := http.Get(url) //獲取url的內容。
20     if err != nil {
21         log.Fatal(err)
22     }
23     defer resp.Body.Close()  //千萬要關閉連接,否則會形成資源泄露。
24     if resp.StatusCode != http.StatusOK{ //若是返回狀態出現錯誤,就拋出錯誤。
25         log.Fatal(resp.Status)
26     }
27     io.Copy(os.Stdout,resp.Body) //將正常的結果輸出到屏幕上,並不會佔用內存。
28 }
  1 [root@yinzhengjie tmp]# more http.go 
  2 package main
  3 
  4 import (
  5         "net/http"
  6         "log"
  7         "io"
  8         "os"
  9 )
 10 
 11 func main() {
 12         url := "http://www.xiaohuar.com"  //定義一個URl,也就是咱們要爬的網站。
 13         resp,err := http.Get(url)
 14         if err != nil {
 15                 log.Fatal(err)
 16         }
 17         defer resp.Body.Close()  //千萬要關閉連接,否則會形成資源泄露。
 18         if resp.StatusCode != http.StatusOK{ //若是返回狀態出現錯誤,就拋出錯誤。
 19                 log.Fatal(resp.Status)
 20         }
 21         io.Copy(os.Stdout,resp.Body) //將結果輸出到屏幕上,並不會佔用內存。
 22 }
 23 
 24 [root@yinzhengjie tmp]# 
 25 [root@yinzhengjie tmp]# 
 26 [root@yinzhengjie tmp]# go run http.go 
 27 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 28 <html xmlns="http://www.w3.org/1999/xhtml">
 29 <head>
 30 <meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
 31 <meta http-equiv="Cache-Control" content="no-transform"/>
 32 <meta http-equiv="Cache-Control" content="no-siteapp"/>
 33 <link rel="alternate" media="only screen and(max-width: 640px)" href="http://m.xiaohuar.com/">
 34 <title>-УУtitle><meta name="keywords" content="УУ
 35 
 36                                                   <meta name="description" content="2015УУУƬУѧУУ">
 37 <link rel="Shortcut Icon" type="image/x-icon" href="http://www.xiaohuar.com/favicon.ico"/>
 38 <link type="text/css" rel="stylesheet" href="http://www.xiaohuar.com/skin/meizi/css/global.css"/>
 39 <link type="text/css" rel="stylesheet" href="http://www.xiaohuar.com/skin/meizi/css/index2.css"/>
 40 <link href="http://www.xiaohuar.com/skin/meizi/css/a.css" rel="stylesheet" type="text/css"/>
 41 <script type="text/javascript" src="http://www.xiaohuar.com/skin/meizi/js/jquery.min.js"></script>
 42 <script type="text/javascript" src="http://www.xiaohuar.com/skin/meizi/js/global.js"></script>
 43 <script src="http://www.xiaohuar.com/skin/default/js/tophone.js" type="text/javascript"></script><script type="text/javascript">uaredirect("http://m.xiaohuar.com");</script>
 44 <script type="text/javascript" src="http://www.xiaohuar.com/skin/meizi/js/focus.js"></script>
 45 <script type="text/javascript" src="http://www.xiaohuar.com/skin/default/js/index.js"></script>
 46 <script type="text/javascript" src="http://www.xiaohuar.com/skin/meizi/js/imglazyload.js"></script>
 47 <meta property="qc:admins" content="10572731676011705126375"/>
 48 </head>
 49 <body>
 50 <div class="g-hd"><div class="m-nav"><h1 class="m-logo"><a href="http://www.xiaohuar.com" title="У">У</a></h1><ul id="menu-nav" class="main-menu"><li id="menu-item-14599" class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-home menu-item-14599"><a title="" href="http://www.xiaohuar.com/"></a></li><li id="menu-item-32780" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-32780"><a title="Уhref="http://www.xiaohuar.com/hua/">Уa></li><li id="menu-item-32781" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-32781"><a title="Уhref="http://www.xiaohuar.com/2014.html">Уa></li><li id="menu-item-32783" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-32783"><a title="Уhref="http://www.xiaohuar.com/xiaocao/">Уa></li><li id="menu-item-32782" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-32782"><a title="УƵ" href="http://www.xiaohuar.com/v/"></a></li><li id="menu-item-14595"><a title="У href="http://www.xiaohuar.com/mm/">Уa></li><li id="menu-item-14596" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-14596"><a title="Уhref="http://www.xiaohuar.com/nvshen/" target="_blank">Ůa></li></ul><div class="searchform"><script type="text/javascript">document.write(unescape('%3Cdiv id="bdcs"%3E%3C/div%3E%3Cscript charset="utf-8" src="http://znsv.baidu.com/customer_search/api/js?sid=16660441808226271668') + '&plate_url=' + (encodeURIComponent(window.location.href)) + '&t=' + (Math.ceil(new Date()/3600000)) + unescape('"%3E%3C/script%3E'));</script></div></div></div>
 51 <div style="margin-top:80px;">
 52 </div><div class="jiaodian">
 53  
 54 <div id="inner">
 55 <div class="hot-event">
 56 <div class="switch-nav"><a href="#" onclick="return false;" class="prev"><i class="ico i-prev"></i><span class="hide-clip">span><span class="blackbg"></span></a><a href="#" onclick="return false;" class="next"><i class="ico i-next"></i><span class="hide-clip">span><span class="blackbg"></span></a></div>
 57 <div class="event-item" style="display: block;"><a href="http://www.xiaohuar.com/html/zhongxue/" target="_blank" class="banner"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://www.xiaohuar.com/images/banner/2.jpg" class="photo" style="width: 1000px; height: 400px;" alt="Ůϲ˽></a></div><div class="event-item" style="display: none;"><a href="http://www.xiaohuar.com/html/dasai/" target="_blank" class="banner"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://www.xiaohuar.com/images/banner/3.jpg" class="photo" style="width: 1000px; height: 400px;" alt="д></a></div><div class="event-item" style="display: none;"><a href="http://www.xiaohuar.com/p-6-27.html" target="_blank" class="banner"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://www.xiaohuar.com/images/banner/4.jpg" class="photo" style="width: 1000px; height: 400px;" alt="ɭ></a></div><div class="event-item" style="display: none;"><a href="http://www.xiaohuar.com/p-6-26.html" target="_blank" class="banner"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://www.xiaohuar.com/images/banner/5.jpg" class="photo" style="width: 1000px; height: 400px;" alt=""/></a></div><div class="event-item" style="display: none;"><a href="http://www.xiaohuar.com/p-6-25.html" target="_blank" class="banner"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://www.xiaohuar.com/images/banner/6.jpg" class="photo" style="width: 1000px; height: 400px;" alt="ʷ欶/></a></div>
 58 <div class="switch-tab">
 59 <a href="#" onclick="return false;" hidefocus="true" class="current">1</a>
 60 <a href="#" onclick="return false;" hidefocus="true">2</a>
 61 <a href="#" onclick="return false;" hidefocus="true">3</a>
 62 <a href="#" onclick="return false;" hidefocus="true">4</a>
 63 <a href="#" onclick="return false;" hidefocus="true">5</a>
 64 </div>
 65 </div>
 66 </div>
 67 <script type="text/javascript">
 68        $('#inner').nav({ t: 2000, a: 1000 });
 69        </script>
 70  
 71 </div>
 72 <div class="all_1000">
 73 <div class="jingxuan ">
 74 <div class="title1000"><div class="jingxuan "><div class="title1000"><div class="title jx"><a>ͼƬ</a></div>
 75 <div class="titleleft"><a href="http://www.xiaohuar.com/news/" target="_blank">Уa>|<a href="http://www.xiaohuar.com/meinv/" target="_blank"></a>|<a href="http://www.xiaohuar.com/2014.html" target="_blank">У</a>|<a href="http://www.xiaohuar.com/daxue/" target="_blank">Уa>|<a href="http://www.xiaohuar.com/hot/" target="_blank"></a></div><div style="float:right;padding-top:10px;"><div class="bdsharebuttonbox"><a href="#" class="bds_more" data-cmd="more"></a><a href="#" class="bds_qzone" data-cmd="qzone" title=""></a><a href="#" class="bds_tsina" data-cmd="tsina" title="</a><a href="#" class="bds_tqq" data-cmd="tqq" title="Ѷ΢</a><a href="#" class="bds_weixin" data-cmd="weixin" title="</a><a href="#" class="bds_sqq" data-cmd="sqq" title=""></a><a href="#" class="bds_tieba" data-cmd="tieba" title="</a></div>
 76 <script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"24"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script></div></div>
 77 </div>
 78 </div>
 79 <div class="img1000">
 80 <ul><li><a href="http://www.xiaohuar.com/hua/" target="_blank" title="У<i></i><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://www.xiaohuar.com/images/banner/a.jpg" alt="У></a></li><li><a href="http://www.xiaohuar.com/xiaocao/" target="_blank" title="У<i></i><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://www.xiaohuar.com/images/banner/b.jpg" alt="У></a></li><li><a href="http://www.xiaohuar.com/mm/" target="_blank" title="У<i></i><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://www.xiaohuar.com/images/banner/c.jpg" alt="У></a></li><li><a href="http://www.xiaohuar.com/meinv/" target="_blank" title=""><i></i><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://www.xiaohuar.com/images/banner/d.jpg" alt=""/></a></li></ul>
 81 </div>
 82 </div>
 83 <div class="clear"></div><div class="adv100090" style="margin-top: 15px;text-align: center;padding: 20px 0px;background-color: #f5f5f5;"> <script type="text/javascript">
 84     /*banner*/
 85     var cpro_id = "u2170109";
 86 </script>
 87 <script type="text/javascript" src="http://cpro.baidustatic.com/cpro/ui/c.js"></script>
 88 </div>
 89 <div class="all_lanmu ">
 90 <div class="title1000"><div class="title xg"><a>Уa></div><div class="more"></div>
 91 </div>
 92 <ul class="twoline">
 93 <li><a href="http://www.xiaohuar.com/p-1-1933.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20170628/f3d06ef49965aedbe18286a2f221fd9f.jpg"/></a><a href="http://www.xiaohuar.com/p-1-1933.html" target="_blank"><span>ҵѧԺУspan></a><b class="b1">ҵѧԺ</b><b class="b2">81</b></li>
 94 <li><a href="http://www.xiaohuar.com/p-1-1932.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20170626/0ab1d89f54c90df477a90aa533ceea36.jpg"/></a><a href="http://www.xiaohuar.com/p-1-1932.html" target="_blank"><span>ְҵѧԺУ</span></a><b class="b1">ְҵѧԺ</b><b class="b2">4</b></li>
 95 <li><a href="http://www.xiaohuar.com/p-1-1931.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20170619/e0456729d4dcbea569a1acbc6a47ab69.jpg"/></a><a href="http://www.xiaohuar.com/p-1-1931.html" target="_blank"><span>ְҵѧԺУ</span></a><b class="b1">ְҵѧԺ</b><b class="b2">21</b></li>
 96 <li><a href="http://www.xiaohuar.com/p-1-1928.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20170612/1f6620771e2815d21f37d481fa8311e6.png"/></a><a href="http://www.xiaohuar.com/p-1-1928.html" target="_blank"><span>ɽУ</span></a><b class="b1">ɽ</b><b class="b2">32</b></li>
 97 <li><a href="http://www.xiaohuar.com/p-1-1926.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20170604/ec3794d0d42b538bf4461a84dac32509.jpg"/></a><a href="http://www.xiaohuar.com/p-1-1926.html" target="_blank"><span>ʵ</span></a><b class="b1">ʵb><b class="b2">36</b></li>
 98 <li><a href="/p-1-338.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://www.xiaohuar.com/d/file/20150313150700127.jpg"/></a><a href="/p-1-338.html" target="_blank"><span>ѧԺУѩcc</span></a><b class="b1">ѧԺ</b><b class="b2">106</b></li>
 99 <li><a href="/p-1-165.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://www.xiaohuar.com/d/file/20150306205302174.jpg"/></a><a href="/p-1-165.html" target="_blank"><span>ѧԺУ</span></a><b class="b1">ѧԺ</b><b class="b2">78</b></li>
100 <li><a href="http://www.xiaohuar.com/p-1-667.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://www.xiaohuar.com/d/file/20150716115704192.jpg"/></a><a href="http://www.xiaohuar.com/p-1-667.html" target="_blank"><span>ѧԺУspan></a><b class="b1">ѧԺ</b><b class="b2">150</b></li>
101 <li><a href="/p-1-390.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://www.xiaohuar.com/d/file/20150313162704133.jpg"/></a><a href="/p-1-390.html" target="_blank"><span>У</span></a><b class="b1"></b><b class="b2">351</b></li>
102 <li><a href="/p-1-363.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/aaa5491c03fce0c6c3806c838fd64980.jpg"/></a><a href="/p-1-363.html" target="_blank"><span>У</span></a><b class="b1"></b><b class="b2">220</b></li>
103 </ul>
104 </div>
105 <div class="all_1000">
106 <div class="title1000"><div class="title mx"><a href="http://www.xiaohuar.com/news/" target="_blank">Уa></div><div class="more"></div>
107 </div>
108 <div class="mx_left">
109 <div class="mx240">
110 <div class="img240 piclunbo">
111 <a href="http://www.xiaohuar.com/hot/188.html" class='on' target="_blank"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/news/20160328/1459134125894888.jpg" width="240" height="150" alt="ǫע<em></em><span>ǫעpan></a><a href="http://www.xiaohuar.com/p-5-148.html" target="_blank"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/news/20151027/1445918569133368.jpg" width="240" height="150" alt="ѧԺУ><em></em><span>ѧԺУspan></a>
112 <a href="http://www.xiaohuar.com/p-5-145.html" target="_blank"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/news/20151026/1445832517110699.jpg" width="240" height="150" alt="<em></em><span>pan></a>
113 </div>
114 <ul> <li class='kuang'><a href="javascript:;"><i></i><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/news/20160328/1459134125894888.jpg" width="72" height="50" alt="ǫע</a></li> <li><a href="javascript:;"><i></i><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/news/20151027/1445918569133368.jpg" width="72" height="50" alt="ѧԺУ></a></li>
115 <li><a href="javascript:;"><i></i><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/news/20151026/1445832517110699.jpg" width="72" height="50" alt="</a></li>
116 </ul> </div>
117 <div class="mx240_list">
118 <div class="title240"><a href="http://www.xiaohuar.com/news/" target="_blank"></a></div>
119 <ul>
120 <li><a href="http://www.xiaohuar.com/news-1-1933.html" target="_blank" title="">ҵѧԺУa></li> <li><a href="http://www.xiaohuar.com/news-1-1932.html" target="_blank" title="ְҵѧԺУ</a></li> <li><a href="http://www.xiaohuar.com/news-1-1931.html" target="_blank" title="֣">ְҵѧԺУ</a></li> <li><a href="http://www.xiaohuar.com/news-1-1928.html" target="_blank" title="ɽУ</a></li> <li><a href="http://www.xiaohuar.com/hot/188.html" target="_blank" title="ǫע</a></li> <li><a href="http://www.xiaohuar.com/hot/183.html" target="_blank" title="ϲ">ϲ</a></li> <li><a href="http://www.xiaohuar.com/hot/182.html" target="_blank" title="MM">MM</a></li> <li><a href="http://www.xiaohuar.com/hot/179.html" target="_blank" title="ŮChoi Somi)΢ʾ">ŮChoi Somi)΢ʾ</a></li> <li><a href="http://www.xiaohuar.com/hot/168.html" target="_blank" title="ô">ô</a></li> </ul>
121 </div>
122 </div>
123 <div class="mx_con">
124 <div class="mx_con_top">
125 <div class="div1"><a href="http://www.xiaohuar.com/p-7-10.html" target="_blank"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" width="200" lazysrc="/d/file/20150827/f341b4ac6aaadd8d935c9de04cc5d812.jpg"/><span>jolie</span><em></em></a></div>
126 <div class="div2"><div class="img125120">
127 <a href="http://www.xiaohuar.com/p-1-1548.html" target="_blank"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" width="125" lazysrc="/d/file/20160412/434d0f660ad823fa3d0b12b115a6af99.jpg"/><span>ӯ</span><em></em></a> </div><div class="clearh10"></div><div class="img125170"> <a href="/p-1-328.html" target="_blank"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://www.xiaohuar.com/d/file/20141204065514172.jpg" width="125"/><span></span><em></em></a> </div></div>
128 <div class="div2"><div class="img125170"><a href="http://www.xiaohuar.com/p-1-1854.html" target="_blank"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" width="125" lazysrc="/d/file/20170227/06eb36fb8d8708551b7a53f8e07e77a7.jpg"/><span>span><em></em></a> </div><div class="clearh10"></div><div class="img125120"><a href="/p-1-126.html" target="_blank"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/c34082612850c3a01922c960c2384bbf.jpg" width="125"/><span>span><em></em></a> </div></div>
129 </div>
130 <div class="mx_con_down">
131 <div class="title470">Ůdiv><div class="img155200"><a href="http://www.xiaohuar.com/p-6-3.html" target="_blank"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://www.xiaohuar.com/d/file/20150815123444171.jpg" alt="Yurisa"/><span>Yurisa-</span><em></em></a></div>
132 <div class="ulbox">
133 <ul><li><a href="http://www.xiaohuar.com/p-5-48.html" target="_blank"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://www.xiaohuar.com/d/file/news/20150815/1439615307134745.jpg" alt="><span>span><em></em></a></li><li><a href="http://www.xiaohuar.com/p-5-49.html" target="_blank"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://www.xiaohuar.com/d/file/news/20150815/1439615732117201.jpg" alt="><span>span><em></em></a></li><li><a href="http://www.xiaohuar.com/p-5-47.html" target="_blank"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://www.xiaohuar.com/d/file/news/20150815/1439615048116633.jpg" alt="><span>span><em></em></a></li><li><a href="http://www.xiaohuar.com/p-1-681.html" target="_blank"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://www.xiaohuar.com/d/file/news/20150815/1439616247184348.jpg" alt="><span>span><em></em></a></li><li><a href="http://www.xiaohuar.com/p-1-749.html" target="_blank"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://img.1985t.com/uploads/previews/2014/12/0-rcAIKA.jpg" alt="><span>span><em></em></a></li><li><a href="http://www.xiaohuar.com/p-1-136.html" target="_blank"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://img.1985t.com/uploads/previews/2014/12/0-ywgsac.jpg" alt="><span>span><em></em></a></li>
134 <div class="clear"></div>
135 </ul>
136 </div>
137 </div>
138 </div>
139 <div class="mx_right">
140 <div class="mx_alaal"><div class="title240">Уѯ</div><div class="mx_search">
141 <form method="get" target="_self" action="/star/section">
142 <div class="search_ipt"><input name="keywords" class="s_ipt" id="searchstar" autocomplete="off" type="text" value="" onfocus="if(this.value==''){this.value=''}; this.style.color='#666'" onblur="if(this.value==''){this.value=''}; this.style.color='#C0C0C0'" style="color:#C0C0C0;"/>
143 <input type="hidden" id="filed_quyu" name="quyu" value="0"/>
144 <input type="hidden" id="filed_fenlei" name="fenlei" value="0"/>
145 <input class="serch_btn" type="submit" value="">
146 </div>
147 </form>
148 </div>
149 <div class="taglist_outer"><dl class="taglist"><dt>/dt><dd id="div_genre" data='quyu'><a href="#" data="1"></a><a href="#" data="2"></a><a href="#" data="3">Ůa><a href="#" data="4"></a></dd></dl>
150 <div class="tagsearch">Уa href="http://www.xiaohuar.com/p-1-3.html" target="_blank">MM</a><a href="http://www.xiaohuar.com/p-1-563.html" target="_blank">΢С΢</a><a href="http://www.xiaohuar.com/daxue/xiamen/" target="_blank"></a><a href="http://www.xiaohuar.com/p-1-95.html" target="_blank">a><a href="http://www.xiaohuar.com/p-1-136.html" target="_blank">a><a href="http://www.xiaohuar.com/p-1-169.html" target="_blank">a><a href="http://www.xiaohuar.com/p-1-290.html" target="_blank">a><a href="http://www.xiaohuar.com/p-1-5.html" target="_blank"></a></div>
151 </div>
152 </div>
153 <div class="big_lunhuan">
154  
155 <div class="mod-hd"><div class="mod-hd-title"></div></div>
156  
157  
158 <style>.mypicchange ul{border-top:1px solid #eaeaea;}.mypicchange ul li{border:1px solid #eaeaea;border-top:0px;height:40px;line-height:40px;}.mypicchange ul li .yuletit{padding:0px 10px;height:40px;line-height:40px;overflow:hidden;}.mypicchange ul li .yulepic{display:none;}.mypicchange ul li.on{height:auto;}.mypicchange ul li.on .yuletit{display:none;}.mypicchange ul li.on .yulepic{display:block;}.mypicchange ul li.on .yulepic img{width:238px;}.mypicchange ul li .yulepic h3{padding:0px 10px;font-size:14px;height:40px;line-height:40px;overflow:hidden;text-align:center;background-color:#f7f7f7;}.mypicchange ul li .yulepic h3 a{color:#c39;display:block;}</style>
159 <script>
160                    $(function(){
161                            $('.mypicchange ul li').bind('mouseover',function(){
162                                    $('.mypicchange ul li').removeClass('on');
163                                    $(this).addClass('on');
164                            });
165                    });
166                    </script>
167 <div class="accordion-news-side">
168 <div class="mypicchange">
169 <ul><li class='on'><div class="yuletit"><a href="http://www.xiaohuar.com/p-5-50.html">a></div><div class="yulepic"><h3><a href="http://www.xiaohuar.com/p-5-50.html">a></h3><p><a href="http://www.xiaohuar.com/p-5-50.html" title="<img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://www.xiaohuar.com/d/file/news/20150815/1439617608990548.jpg" width="238" alt="</a></p></div></li><li><div class="yuletit"><a href="http://www.xiaohuar.com/p-1-310.html">У</a></div><div class="yulepic"><h3><a href="http://www.xiaohuar.com/p-1-310.html">У</a></h3><p><a href="http://www.xiaohuar.com/p-1-310.html" title="У"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://www.xiaohuar.com/d/file/news/20150815/1439618030131259.jpg" width="238" alt="У"></a></p></div></li><li><div class="yuletit"><a href="http://www.xiaohuar.com/p-1-64.html">У</a></div><div class="yulepic"><h3><a href="http://www.xiaohuar.com/p-1-64.html">У</a></h3><p><a href="http://www.xiaohuar.com/p-1-64.html" title="У"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://www.xiaohuar.com/d/file/news/20150815/1439618379649349.jpg" width="238" alt="У"></a></p></div></li><li><div class="yuletit"><a href="http://www.xiaohuar.com/p-1-752.html">Ůͼ бҲ</a></div><div class="yulepic"><h3><a href="http://www.xiaohuar.com/p-1-752.html">Ůͼ бҲ</a></h3><p><a href="http://www.xiaohuar.com/p-1-752.html" title="Ůͼ бҲ"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://www.xiaohuar.com/d/file/20150815141329100.jpg" width="238" alt="Ůͼ бҲ"></a></p></div></li><li><div class="yuletit"><a href="http://www.xiaohuar.com/p-1-383.html">Уa></div><div class="yulepic"><h3><a href="http://www.xiaohuar.com/p-1-383.html">Уa></h3><p><a href="http://www.xiaohuar.com/p-1-383.html" title="У<img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://www.xiaohuar.com/d/file/20150815141814102.jpg" width="238" alt="У</a></p></div></li></ul>
170 </div>
171 </div>
172  
173 </div>
174 </div>
175 </div>
176 <div class="all_lanmu ">
177 <div class="title1000"><div class="title mytitle myw_sexy"><a href="/mm/" target="_blank">Уa></div><div class="more"><a href="/mm/" target="_blank">MORE+</a></div></div>
178 <ul class="twoline">
179 <li><a href="http://www.xiaohuar.com/p-4-639.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://www.xiaohuar.com/d/file/20150221175512120.jpg"/></a><a href="http://www.xiaohuar.com/p-4-639.html" target="_blank"><span>ʯʨѧУ</span></a><b class="b1">ʯʨѧ</b><b class="b2">91</b></li>
180 <li><a href="http://www.xiaohuar.com/p-4-706.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/d33b2cae4fdfa7110fa8049db325838f.jpg"/></a><a href="http://www.xiaohuar.com/p-4-706.html" target="_blank"><span>loly~~~~~~~У~~~~</span></a><b class="b1">loly~~~~~~~</b><b class="b2">69</b></li>
181 <li><a href="http://www.xiaohuar.com/p-4-486.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://www.xiaohuar.com/d/file/20150414092659161.jpg"/></a><a href="http://www.xiaohuar.com/p-4-486.html" target="_blank"><span>УֱгŴ˽span></a><b class="b1"></b><b class="b2">75</b></li>
182 <li><a href="http://www.xiaohuar.com/p-4-691.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/9bfe870df5ea859c219b6f2733e513b1.jpg"/></a><a href="http://www.xiaohuar.com/p-4-691.html" target="_blank"><span>У</span></a><b class="b1"></b><b class="b2">85</b></li>
183 <li><a href="http://www.xiaohuar.com/p-4-1122.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20160109/7f860f71d979a57531132f91677376bb.jpg"/></a><a href="http://www.xiaohuar.com/p-4-1122.html" target="_blank"><span>Уspan></a><b class="b1"></b><b class="b2">84</b></li>
184 <li><a href="http://www.xiaohuar.com/p-4-867.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20151003/11f8c32b40eab5269d18e68d51185d8d.jpg"/></a><a href="http://www.xiaohuar.com/p-4-867.html" target="_blank"><span></span></a><b class="b1">b><b class="b2">64</b></li>
185 <li><a href="http://www.xiaohuar.com/p-4-1099.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20151231/ddb79b6dcdbc876059cd6db9730d7656.jpg"/></a><a href="http://www.xiaohuar.com/p-4-1099.html" target="_blank"><span>DZɽҰկУ</span></a><b class="b1">DZɽҰկ</b><b class="b2">48</b></li>
186 <li><a href="http://www.xiaohuar.com/p-4-797.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20150902/890c8a533c0346c19bb84ff90a36e4fd.jpg"/></a><a href="http://www.xiaohuar.com/p-4-797.html" target="_blank"><span>У</span></a><b class="b1"></b><b class="b2">58</b></li>
187 <li><a href="http://www.xiaohuar.com/p-4-922.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20151103/d89e18e42269f9169dfcffba836f2795.jpg"/></a><a href="http://www.xiaohuar.com/p-4-922.html" target="_blank"><span>ְҵѧԺУ</span></a><b class="b1">ְҵѧԺ</b><b class="b2">58</b></li>
188 <li><a href="http://www.xiaohuar.com/p-4-1114.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20160107/776911c54ae5ed4f0fe1c3652ce755da.jpg"/></a><a href="http://www.xiaohuar.com/p-4-1114.html" target="_blank"><span>У</span></a><b class="b1"></b><b class="b2">188</b></li>
189 </ul>
190 </div>
191 <div class="all_lanmu ">
192 <div class="title1000"><div class="title mytitle myw_fresh"><a href="/xiaocao/" target="_blank">Уa></div><div class="more"><a href="/xiaocao/" target="_blank">MORE+</a></div></div>
193 <ul class="twoline">
194 <li><a href="http://www.xiaohuar.com/p-2-1930.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20170613/814725f45667309a6066e93b1ad2e378.jpg"/></a><a href="http://www.xiaohuar.com/p-2-1930.html" target="_blank"><span>У</span></a><b class="b1"></b><b class="b2">1</b></li>
195 <li><a href="http://www.xiaohuar.com/p-2-1927.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20170608/f07501a9d1fe9945e2fb96f0890a8d23.jpg"/></a><a href="http://www.xiaohuar.com/p-2-1927.html" target="_blank"><span>ʦѧУspan></a><b class="b1">ʦѧ</b><b class="b2">1600</b></li>
196 <li><a href="http://www.xiaohuar.com/p-2-1915.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20170601/b5ceb0d78d4e2d15f5bf3e9085fdc638.jpg"/></a><a href="http://www.xiaohuar.com/p-2-1915.html" target="_blank"><span>У</span></a><b class="b1"></b><b class="b2">1</b></li>
197 <li><a href="http://www.xiaohuar.com/p-2-1907.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20170528/68f95c381d71baeb3290cf686f75cf6e.jpg"/></a><a href="http://www.xiaohuar.com/p-2-1907.html" target="_blank"><span>ѧУ˼</span></a><b class="b1">ѧ</b><b class="b2">1</b></li>
198 <li><a href="http://www.xiaohuar.com/p-2-1900.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20170505/6de1dfa7b06149a8e4f58d4531f1e0a6.jpg"/></a><a href="http://www.xiaohuar.com/p-2-1900.html" target="_blank"><span>һСУ</span></a><b class="b1">һС</b><b class="b2">1</b></li>
199 <li><a href="http://www.xiaohuar.com/p-2-1899.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20170504/b44a79761757d24941c3f1205630f265.jpg"/></a><a href="http://www.xiaohuar.com/p-2-1899.html" target="_blank"><span>ѧԺУkey</span></a><b class="b1">ѧԺ</b><b class="b2">3</b></li>
200 <li><a href="http://www.xiaohuar.com/p-2-1880.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20170416/55e0a68c6d7b985dca286f24b4a0b4ed.jpg"/></a><a href="http://www.xiaohuar.com/p-2-1880.html" target="_blank"><span>У</span></a><b class="b1"></b><b class="b2">2</b></li>
201 <li><a href="http://www.xiaohuar.com/p-2-1877.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20170413/31572d773f2117c4dd3c1a4552fb64c9.jpg"/></a><a href="http://www.xiaohuar.com/p-2-1877.html" target="_blank"><span>ѧУУԣspan></a><b class="b1">ѧУ</b><b class="b2">2</b></li>
202 <li><a href="http://www.xiaohuar.com/p-2-1876.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20170413/aaeaa82b8eccb31323153201f0d35c69.jpg"/></a><a href="http://www.xiaohuar.com/p-2-1876.html" target="_blank"><span>ѧԺУspan></a><b class="b1">ѧԺ</b><b class="b2">3</b></li>
203 <li><a href="http://www.xiaohuar.com/p-2-1868.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20170404/e1bc3ee2190f02b13a4b65fa78839df8.jpg"/></a><a href="http://www.xiaohuar.com/p-2-1868.html" target="_blank"><span>У.У</span></a><b class="b1">У.</b><b class="b2">3</b></li>
204 </ul>
205 </div>
206 <div class="all_lanmu ">
207 <div class="title1000"><div class="title mytitle myw_beauty"><a href="/meinv/" target="_blank"></a></div><div class="more"><a href="/meinv/" target="_blank">MORE+</a></div></div>
208 <ul class="twoline">
209 <li><a href="http://www.xiaohuar.com/p-6-36.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20151112/6c4f48884832ea2700695b2849628ac5.jpg"/></a><a href="http://www.xiaohuar.com/p-6-36.html" target="_blank"><span>ԡ</span></a><b class="b1">2015-11-12</b><b class="b2">7445</b></li>
210 <li><a href="http://www.xiaohuar.com/p-6-4.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://www.xiaohuar.com/d/file/20150503184242161.jpg"/></a><a href="http://www.xiaohuar.com/p-6-4.html" target="_blank"><span>90rbieͯҡ</span></a><b class="b1">2015-05-03</b><b class="b2">4499</b></li>
211 <li><a href="http://www.xiaohuar.com/p-6-26.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://www.xiaohuar.com/d/file/20150814223831181.jpg"/></a><a href="http://www.xiaohuar.com/p-6-26.html" target="_blank"><span></span></a><b class="b1">2015-08-14</b><b class="b2">10647</b></li>
212 <li><a href="http://www.xiaohuar.com/p-6-44.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20160408/40e4e29b7156e316d4f877d8d0906ff7.jpg"/></a><a href="http://www.xiaohuar.com/p-6-44.html" target="_blank"><span>Ϫдspan></a><b class="b1">2016-04-08</b><b class="b2">4635</b></li>
213 <li><a href="http://www.xiaohuar.com/p-6-12.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://www.xiaohuar.com/d/file/20150630151831172.jpg"/></a><a href="http://www.xiaohuar.com/p-6-12.html" target="_blank"><span>̨ƷShowGirlҦ span></a><b class="b1">2015-06-30</b><b class="b2">5374</b></li>
214 <li><a href="http://www.xiaohuar.com/p-6-24.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://www.xiaohuar.com/d/file/20150713212708135.jpg"/></a><a href="http://www.xiaohuar.com/p-6-24.html" target="_blank"><span>΢MiuMiu ΢</span></a><b class="b1">2015-07-13</b><b class="b2">5493</b></li>
215 <li><a href="http://www.xiaohuar.com/p-6-43.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20160408/8434145de5a9bcd6f06e06a780b8a8b3.jpg"/></a><a href="http://www.xiaohuar.com/p-6-43.html" target="_blank"><span></span></a><b class="b1">2016-04-08</b><b class="b2">2137</b></li>
216 <li><a href="http://www.xiaohuar.com/p-6-17.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://www.xiaohuar.com/d/file/20150702184343113.jpg"/></a><a href="http://www.xiaohuar.com/p-6-17.html" target="_blank"><span>34E~ʯùpan></a><b class="b1">2015-07-02</b><b class="b2">2935</b></li>
217 <li><a href="http://www.xiaohuar.com/p-6-11.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="http://www.xiaohuar.com/d/file/20150602175624110.jpg"/></a><a href="http://www.xiaohuar.com/p-6-11.html" target="_blank"><span>һ˿COSspan></a><b class="b1">2015-06-02</b><b class="b2">3419</b></li>
218 <li><a href="http://www.xiaohuar.com/p-6-42.html" target="_blank" class="xhpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20160408/bf5819982372761ea8c2bcade410fb9b.jpg"/></a><a href="http://www.xiaohuar.com/p-6-42.html" target="_blank"><span>ģѩдspan></a><b class="b1">2016-04-08</b><b class="b2">2587</b></li>
219 </ul>
220 </div>
221 <div class="all_lanmu ">
222 <div class="title1000"><div class="title mytitle myw_model"><a href="/v/" target="_blank">УƵ</a></div><div class="more"><a href="/v/" target="_blank">MORE+</a></div></div>
223 <ul class="oneline" style="height: 230px;"><li><a href="http://www.xiaohuar.com/p-3-97.html" target="_blank" class="vpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20161208/878a9b4f94d401a8c2651f2b04f8c94e.jpg"/></a><a href="http://www.xiaohuar.com/p-3-97.html" target="_blank"><span>,СŶ</span></a><b class="b1">2016-12-08</b><b class="b2">9356</b></li>
224 <li><a href="http://www.xiaohuar.com/p-3-96.html" target="_blank" class="vpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20161113/adbdd1dd3924922398f2f6efc31ffee7.jpg"/></a><a href="http://www.xiaohuar.com/p-3-96.html" target="_blank"><span>ҡƵ</span></a><b class="b1">2016-11-13</b><b class="b2">6575</b></li>
225 <li><a href="http://www.xiaohuar.com/p-3-95.html" target="_blank" class="vpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20161103/c7b58bfaf538f2ede89a4f60b1ecc29b.jpg"/></a><a href="http://www.xiaohuar.com/p-3-95.html" target="_blank"><span>ֱ˿</span></a><b class="b1">2016-11-03</b><b class="b2">10782</b></li>
226 <li><a href="http://www.xiaohuar.com/p-3-94.html" target="_blank" class="vpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20161102/68e926a6a685b1ee0a012e89d626397a.jpg"/></a><a href="http://www.xiaohuar.com/p-3-94.html" target="_blank"><span></span></a><b class="b1">2016-11-02</b><b class="b2">5220</b></li>
227 <li><a href="http://www.xiaohuar.com/p-3-93.html" target="_blank" class="vpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20161102/4bb76725c4d4ac5077b9a1c594c5cbb2.jpg"/></a><a href="http://www.xiaohuar.com/p-3-93.html" target="_blank"><span>΢Ƶ</span></a><b class="b1">2016-11-02</b><b class="b2">14255</b></li>
228 <li><a href="http://www.xiaohuar.com/p-3-92.html" target="_blank" class="vpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20161027/f070412c9571ee1e5cbde31a816f3bad.jpg"/></a><a href="http://www.xiaohuar.com/p-3-92.html" target="_blank"><span>˿span></a><b class="b1">2016-10-27</b><b class="b2">7523</b></li>
229 <li><a href="http://www.xiaohuar.com/p-3-91.html" target="_blank" class="vpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20161027/185dc525e53fcd53cc30dd9e94f41114.jpg"/></a><a href="http://www.xiaohuar.com/p-3-91.html" target="_blank"><span></span></a><b class="b1">2016-10-27</b><b class="b2">8720</b></li>
230 <li><a href="http://www.xiaohuar.com/p-3-90.html" target="_blank" class="vpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20161016/e846aa103fe104b54b4e8a9ede378b9d.jpg"/></a><a href="http://www.xiaohuar.com/p-3-90.html" target="_blank"><span>ԡspan></a><b class="b1">2016-10-16</b><b class="b2">8271</b></li>
231 <li><a href="http://www.xiaohuar.com/p-3-89.html" target="_blank" class="vpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20161016/64a7e1893ccbc07a302a176480df3e79.jpg"/></a><a href="http://www.xiaohuar.com/p-3-89.html" target="_blank"><span>ɬ ͬһŮ</span></a><b class="b1">2016-10-16</b><b class="b2">8097</b></li>
232 <li><a href="http://www.xiaohuar.com/p-3-88.html" target="_blank" class="vpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20160619/5c3ede0e1d50f38adbfe8c34afd46771.jpg"/></a><a href="http://www.xiaohuar.com/p-3-88.html" target="_blank"><span></span></a><b class="b1">2016-06-19</b><b class="b2">14526</b></li>
233 </ul>
234 </div>
235 <div class="all_lanmu ">
236 <div class="title1000"><div class="title mytitle myw_battoo"><a href="/news/" target="_blank">У̬</a></div><div class="more"><a href="/news/" target="_blank">MORE+</a></div></div>
237 <ul class="oneline" style="height: 230px;"><li><a href="http://www.xiaohuar.com/p-5-25.html" target="_blank" class="vpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/bac1f0d8253b4e157fbf40b8a3edab56.jpg"/></a><a href="http://www.xiaohuar.com/p-5-25.html" target="_blank"><span>У/span></a><b class="b1">2015-07-16</b><b class="b2">2147</b></li>
238 <li><a href="http://www.xiaohuar.com/p-5-50.html" target="_blank" class="vpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/a0bbfc787c3179a029155871063cee0f.jpg"/></a><a href="http://www.xiaohuar.com/p-5-50.html" target="_blank"><span>span></a><b class="b1">2015-08-15</b><b class="b2">3856</b></li>
239 <li><a href="http://www.xiaohuar.com/p-5-33.html" target="_blank" class="vpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/news/20150807/1438960820583080.jpg"/></a><a href="http://www.xiaohuar.com/p-5-33.html" target="_blank"><span>̨ ̨</span></a><b class="b1">2015-08-07</b><b class="b2">2874</b></li>
240 <li><a href="http://www.xiaohuar.com/p-5-51.html" target="_blank" class="vpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/9520c71801cd4896ff3c7346b542b84d.jpg"/></a><a href="http://www.xiaohuar.com/p-5-51.html" target="_blank"><span>У</span></a><b class="b1">2015-08-15</b><b class="b2">2430</b></li>
241 <li><a href="http://www.xiaohuar.com/p-5-71.html" target="_blank" class="vpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20150830/576cf065a7d34716f0a8c3b27c546098.jpg"/></a><a href="http://www.xiaohuar.com/p-5-71.html" target="_blank"><span>רԺУspan></a><b class="b1">2015-08-30</b><b class="b2">3263</b></li>
242 <li><a href="http://www.xiaohuar.com/p-5-105.html" target="_blank" class="vpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/news/20151017/1445074354107162.jpg"/></a><a href="http://www.xiaohuar.com/p-5-105.html" target="_blank"><span>ѧԺУ˭</span></a><b class="b1">2015-10-17</b><b class="b2">1639</b></li>
243 <li><a href="http://www.xiaohuar.com/p-5-54.html" target="_blank" class="vpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/news/20150817/1439782814996443.jpg"/></a><a href="http://www.xiaohuar.com/p-5-54.html" target="_blank"><span>΢Ƭ</span></a><b class="b1">2015-08-17</b><b class="b2">2582</b></li>
244 <li><a href="http://www.xiaohuar.com/p-5-39.html" target="_blank" class="vpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/news/20150812/1439349313115531.jpg"/></a><a href="http://www.xiaohuar.com/p-5-39.html" target="_blank"><span>¶ǰspan></a><b class="b1">2015-08-12</b><b class="b2">1251</b></li>
245 <li><a href="http://www.xiaohuar.com/p-5-69.html" target="_blank" class="vpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/20150828/533b346740f18ad15551a3983f3ec333.jpg"/></a><a href="http://www.xiaohuar.com/p-5-69.html" target="_blank"><span>УУԪspan></a><b class="b1">2015-08-28</b><b class="b2">1465</b></li>
246 <li><a href="http://www.xiaohuar.com/p-5-145.html" target="_blank" class="vpic"><img src="http://www.xiaohuar.com/skin/meizi/images/grey.gif" lazysrc="/d/file/news/20151026/1445832517110699.jpg"/></a><a href="http://www.xiaohuar.com/p-5-145.html" target="_blank"><span>pan></a><b class="b1">2015-10-26</b><b class="b2">2540</b></li>
247 </ul>
248 </div>
249 <div class="friendlinks"><div class="linkbt"><h2></h2></div><p> <a href="http://www.dxsabc.com/" target="_blank"></a> <a href="http://www.7kk.com/" target="_blank">ͼƬ</a>
250 <a href="http://hufu.onlylady.com/" target="_blank"></a> <a href="http://www.cooltuku.com" target="_blank"></a> <a href="http://www.4j4j.cn" target="_blank"></a> <a href="http://www.omtxw.com" target="_blank">ŷ</a><a href="http://www.17sucai.com" target="_blank">a> <a href="http://www.iqingren.com" target="_blank">a> <a href="http://www.zhw123.cc">ŮͼƬ</a> <a href="http://www.xiaohuar.com/" target="_blank">Уa><a href="http://jiaoyu.baidu.com/beauty/index/" rel="nofollow" target="_blank">ѧa> <a href="http://www.sumiaozhijia.com/" target="_blank"></a> <a href="http://www.zeihaoxiao.com/" target="_blank">Ц</a> <a href="http://www.showself.com" target="_blank"></a> <a href="http://www.xiannvw.com" target="_blank"></a>
251 </p>
252 </div>
253 </div>
254 <div class="indexfooter">
255 <div class="foot"><div class="f_about"><ul><li><a href="http://www.xiaohuar.com/html/about.html" target="_blank"></a></li><li><a href="http://www.xiaohuar.com/html/about.html#content2" target="_blank"></a></li><li class="foot4"></li><li><a href="/about.html#content3" target="_blank"></a></li><li><a href="http://www.xiaohuar.com/html/about.html#content4" target="_blank"></a></li></ul></div>
256 <p><a href="http://www.xiaohuar.com/">У</a> href="http://www.xiaohuar.com/">ȫѧУƬ</a>ɢͬУͼƬ href="http://www.xiaohuar.com/">УƬ</a>ԭУƬr/><a href="http://www.xiaohuar.com/html/sitemap.htm">Уa> &#169; 2009-2015 All Rights Reserved www.xiaohuar.com   class="__cf_email__" href="/cdn-cgi/l/email-protection" data-cfemail="c0f2f1f1f2f4f9f2f3f680b1b1eea3afad">[email&#160;protected]</a><script data-cfhash='f9e31' type="text/javascript">/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */</script> P006982 <script language="javascript" type="text/javascript" src="http://js.users.51.la/17172513.js"></script></p>
257 </div>
258 </div>
259 <div id="back-to-top" class="back-to-top"><a target="_self" href="javascript:void(0);" id="back-to-top-btn">&nbsp;</a></div>
260 <script type="text/javascript" src="http://www.xiaohuar.com/skin/meizi/js/IE6Top.js"></script>
261 <div id="cbbfixed" style="bottom: 366px;_bottom: 0px;">
262 <div class="dingyue">
263 <a href="javascript:;"></a>
264 <div class="qqdingyue">
265  
266 <script>var nId = "b8f6592311f7b82244e30894c7c84632de2c2675bb9329e6",nWidth="auto",sColor="light",sText=";</script>
267 <script src="http://list.qq.com/zh_CN/htmledition/js/qf/page/qfcode.js" charset="gb18030"></script>
268 </div>
269 </div>
270 <a id="cweixin" href="#"><span></span><div></div></a>
271 <div class="jianyi"><a href="http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=aFpZWVpcUVpbXigZGUYLBwU" target="_blank"></a></div></div>
272 <script>
273 var _hmt = _hmt || [];
274 (function() {
275   var hm = document.createElement("script");
276   hm.src = "//hm.baidu.com/hm.js?0dfa94cc970f5368ddbe743609970944";
277   var s = document.getElementsByTagName("script")[0]; 
278   s.parentNode.insertBefore(hm, s);
279 })();
280 </script><script type="text/javascript">
281     /**/
282     var cpro_id = "u1960876";
283 </script>
284 <script type="text/javascript" src="http://cpro.baidustatic.com/cpro/ui/f.js"></script><script type="text/javascript">
285     /*pic*/
286     var cpro_id = "u1968034";
287 </script>
288 <script type="text/javascript" src="http://cpro.baidustatic.com/cpro/ui/i.js"></script>
289 </body>
290 </html>[root@yinzhengjie tmp]# 
以上代碼執行結果在這裏

 

2.「net/url」模塊用法展現;

  「net/url」模塊中咱們會用到一個解析方法,它能夠解析url使用的協議,主機名,當前路徑,請求信息,用戶信息,當前錨點等等。

 1 /*
 2 #!/usr/bin/env gorun
 3 @author :yinzhengjie
 4 Blog:http://www.cnblogs.com/yinzhengjie/tag/GO%E8%AF%AD%E8%A8%80%E7%9A%84%E8%BF%9B%E9%98%B6%E4%B9%8B%E8%B7%AF/
 5 EMAIL:y1053419035@qq.com
 6 */
 7 
 8 package main
 9 
10 import (
11     "os"
12     "net/url"
13     "log"
14     "fmt"
15 )
16 
17 func main() {
18     s := os.Args[1]
19     u,err := url.Parse(s)
20     if err != nil {
21         log.Fatal(err)
22     }
23     fmt.Println("使用的協議是:",u.Scheme)
24     fmt.Println("主機名稱是:",u.Host)
25     fmt.Println("當前路徑是:",u.Path)
26     fmt.Println("請求信息是:",u.RawQuery)
27     fmt.Println("用戶信息是:",u.User)
28     fmt.Println("當前的錨點是:",u.Fragment)
29 }
 1 [root@yinzhengjie tmp]# more url.go 
 2 /*
 3 #!/usr/bin/env gorun
 4 @author :yinzhengjie
 5 Blog:http://www.cnblogs.com/yinzhengjie/tag/GO%E8%AF%AD%E8%A8%80%E7%9A%84%E8%BF%9B%E9%98%B6%E4%B9%8B%E8%B7%AF/
 6 EMAIL:y1053419035@qq.com
 7 */
 8 
 9 package main
10 
11 import (
12         "os"
13         "net/url"
14         "log"
15         "fmt"
16 )
17 
18 func main() {
19         s := os.Args[1]
20         u,err := url.Parse(s)
21         if err != nil {
22                 log.Fatal(err)
23         }
24         fmt.Println("使用的協議是:",u.Scheme)
25         fmt.Println("主機名稱是:",u.Host)
26         fmt.Println("當前路徑是:",u.Path)
27         fmt.Println("請求信息是:",u.RawQuery)
28         fmt.Println("用戶信息是:",u.User)
29         fmt.Println("當前的錨點是:",u.Fragment)
30 }
31 [root@yinzhengjie tmp]# 
32 [root@yinzhengjie tmp]# 
33 [root@yinzhengjie tmp]# go run url.go http://www.cnblogs.com/yinzhengjie/p/7202796.html
34 使用的協議是: http
35 主機名稱是: www.cnblogs.com
36 當前路徑是: /yinzhengjie/p/7202796.html
37 請求信息是: 
38 用戶信息是: <nil>
39 當前的錨點是: 
40 [root@yinzhengjie tmp]# 
以上代碼用法展現戳這裏

 

3.goquery模塊用法展現;

  作過 Web 開發的,應該都用過或聽過 jQuery,它提供了方便的操做 DOM 的 API。使用 Go 語言作服務器端開發,有時候須要解析 HTML 文件,好比抓取網站內容、寫一個爬蟲等。這時候若是有一個相似 jQuery 的庫可使用,操做 DOM 會很方便,並且,上手也會很快。github.com/PuerkitoBio/goquery 這個庫就實現了相似 jQuery 的功能,讓你能方便的使用 Go 語言操做 HTML 文檔。

  首先,要強調一點,要執行如下代碼須要安裝一個goquery模塊,該模塊用來爬去網站的內容的簡直就是一個神器啊。

 1 /*
 2 #!/usr/bin/env gorun
 3 @author :yinzhengjie
 4 Blog:http://www.cnblogs.com/yinzhengjie/tag/GO%E8%AF%AD%E8%A8%80%E7%9A%84%E8%BF%9B%E9%98%B6%E4%B9%8B%E8%B7%AF/
 5 EMAIL:y1053419035@qq.com
 6 */
 7 
 8 package main
 9 
10 import (
11     "net/http"
12     "log"
13     "github.com/PuerkitoBio/goquery"
14     "fmt"
15 )
16 
17 
18 /*
19     用goquery能夠快速獲取url的標籤。
20 */
21 
22 func main() {
23     url := "http://www.xiaohuar.com"  //定義一個URl,也就是咱們要爬的網站。
24     resp,err := http.Get(url)  ////獲取url的內容,包括請求頭信息都在裏面放着的。
25 
26     if err != nil {
27         log.Fatal(err)
28     }
29     defer resp.Body.Close()  //千萬要關閉連接,否則會形成資源泄露。
30     if resp.StatusCode != http.StatusOK{ //若是返回狀態出現錯誤,就拋出錯誤並終止程序。
31         log.Fatal(resp.Status)
32     }
33     //io.Copy(os.Stdout,resp.Body) //將結果輸出到屏幕上,並不會佔用內存。
34     doc,err := goquery.NewDocumentFromResponse(resp)  //對resp進行過濾,最終會拿到首頁路徑url
35     if err != nil {
36         log.Fatal(err)
37     }
38     doc.Find("img").Each(func(i int, s  *goquery.Selection) { /*表示找到"img"的標籤而後用Each方法遍歷每個圖片路徑。*/
39         link,ok := s.Attr("src") //找到「img」標籤後會將其的「src」的路徑找到,最終也就找到了圖片的路徑。
40         if ok {
41             fmt.Println(link)  //若是存在「src」路徑就打印
42         }else {
43             fmt.Println("抱歉,沒有發現該路徑。")
44         }
45     })
46 }
  1 [root@yinzhengjie tmp]# more goquery.go 
  2 /*
  3 #!/usr/bin/env gorun
  4 @author :yinzhengjie
  5 Blog:http://www.cnblogs.com/yinzhengjie/tag/GO%E8%AF%AD%E8%A8%80%E7%9A%84%E8%BF%9B%E9%98%B6%E4%B9%8B%E8%B7%AF/
  6 EMAIL:y1053419035@qq.com
  7 */
  8 
  9 package main
 10 
 11 import (
 12         "net/http"
 13         "log"
 14         "github.com/PuerkitoBio/goquery"
 15         "fmt"
 16 )
 17 
 18 
 19 /*
 20         用goquery能夠快速獲取url的標籤。
 21 */
 22 
 23 func main() {
 24         url := "http://www.xiaohuar.com"  //定義一個URl,也就是咱們要爬的網站。
 25         resp,err := http.Get(url)  ////獲取url的內容,包括請求頭信息都在裏面放着的。
 26 
 27         if err != nil {
 28                 log.Fatal(err)
 29         }
 30         defer resp.Body.Close()  //千萬要關閉連接,否則會形成資源泄露。
 31         if resp.StatusCode != http.StatusOK{ //若是返回狀態出現錯誤,就拋出錯誤並終止程序。
 32                 log.Fatal(resp.Status)
 33         }
 34         //io.Copy(os.Stdout,resp.Body) //將結果輸出到屏幕上,並不會佔用內存。
 35         doc,err := goquery.NewDocumentFromResponse(resp)  //對resp進行過濾,最終會拿到首頁路徑url
 36         if err != nil {
 37                 log.Fatal(err)
 38         }
 39         doc.Find("img").Each(func(i int, s  *goquery.Selection) { /*表示找到"img"的標籤而後用Each方法遍歷每個圖片路徑。*/
 40                 link,ok := s.Attr("src") //找到「img」標籤後會將其的「src」的路徑找到,最終也就找到了圖片的路徑。
 41                 if ok {
 42                         fmt.Println(link)  //若是存在「src」路徑就打印
 43                 }else {
 44                         fmt.Println("抱歉,沒有發現該路徑。")
 45                 }
 46         })
 47 }
 48 
 49 [root@yinzhengjie tmp]# 
 50 [root@yinzhengjie tmp]# 
 51 [root@yinzhengjie tmp]# go run goquery.go 
 52 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 53 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 54 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 55 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 56 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 57 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 58 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 59 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 60 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 61 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 62 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 63 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 64 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 65 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 66 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 67 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 68 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 69 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 70 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 71 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 72 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 73 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 74 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 75 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 76 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 77 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 78 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 79 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 80 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 81 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 82 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 83 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 84 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 85 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 86 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 87 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 88 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 89 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 90 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 91 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 92 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 93 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 94 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 95 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 96 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 97 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 98 http://www.xiaohuar.com/skin/meizi/images/grey.gif
 99 http://www.xiaohuar.com/skin/meizi/images/grey.gif
100 http://www.xiaohuar.com/skin/meizi/images/grey.gif
101 http://www.xiaohuar.com/skin/meizi/images/grey.gif
102 http://www.xiaohuar.com/skin/meizi/images/grey.gif
103 http://www.xiaohuar.com/skin/meizi/images/grey.gif
104 http://www.xiaohuar.com/skin/meizi/images/grey.gif
105 http://www.xiaohuar.com/skin/meizi/images/grey.gif
106 http://www.xiaohuar.com/skin/meizi/images/grey.gif
107 http://www.xiaohuar.com/skin/meizi/images/grey.gif
108 http://www.xiaohuar.com/skin/meizi/images/grey.gif
109 http://www.xiaohuar.com/skin/meizi/images/grey.gif
110 http://www.xiaohuar.com/skin/meizi/images/grey.gif
111 http://www.xiaohuar.com/skin/meizi/images/grey.gif
112 http://www.xiaohuar.com/skin/meizi/images/grey.gif
113 http://www.xiaohuar.com/skin/meizi/images/grey.gif
114 http://www.xiaohuar.com/skin/meizi/images/grey.gif
115 http://www.xiaohuar.com/skin/meizi/images/grey.gif
116 http://www.xiaohuar.com/skin/meizi/images/grey.gif
117 http://www.xiaohuar.com/skin/meizi/images/grey.gif
118 http://www.xiaohuar.com/skin/meizi/images/grey.gif
119 http://www.xiaohuar.com/skin/meizi/images/grey.gif
120 http://www.xiaohuar.com/skin/meizi/images/grey.gif
121 http://www.xiaohuar.com/skin/meizi/images/grey.gif
122 http://www.xiaohuar.com/skin/meizi/images/grey.gif
123 http://www.xiaohuar.com/skin/meizi/images/grey.gif
124 http://www.xiaohuar.com/skin/meizi/images/grey.gif
125 http://www.xiaohuar.com/skin/meizi/images/grey.gif
126 http://www.xiaohuar.com/skin/meizi/images/grey.gif
127 http://www.xiaohuar.com/skin/meizi/images/grey.gif
128 http://www.xiaohuar.com/skin/meizi/images/grey.gif
129 http://www.xiaohuar.com/skin/meizi/images/grey.gif
130 http://www.xiaohuar.com/skin/meizi/images/grey.gif
131 http://www.xiaohuar.com/skin/meizi/images/grey.gif
132 http://www.xiaohuar.com/skin/meizi/images/grey.gif
133 http://www.xiaohuar.com/skin/meizi/images/grey.gif
134 http://www.xiaohuar.com/skin/meizi/images/grey.gif
135 http://www.xiaohuar.com/skin/meizi/images/grey.gif
136 http://www.xiaohuar.com/skin/meizi/images/grey.gif
137 http://www.xiaohuar.com/skin/meizi/images/grey.gif
138 http://www.xiaohuar.com/skin/meizi/images/grey.gif
139 http://www.xiaohuar.com/skin/meizi/images/grey.gif
140 http://www.xiaohuar.com/skin/meizi/images/grey.gif
141 http://www.xiaohuar.com/skin/meizi/images/grey.gif
142 http://www.xiaohuar.com/skin/meizi/images/grey.gif
143 http://www.xiaohuar.com/skin/meizi/images/grey.gif
144 [root@yinzhengjie tmp]# 
以上代碼執行方式結果戳這裏喲

   若是你想要的代碼擴展性更高,能夠將main函數的代碼定義成一個函數,這樣在主函數調用該函數就行了,代碼以下:

 1 /*
 2 #!/usr/bin/env gorun
 3 @author :yinzhengjie
 4 Blog:http://www.cnblogs.com/yinzhengjie/tag/GO%E8%AF%AD%E8%A8%80%E7%9A%84%E8%BF%9B%E9%98%B6%E4%B9%8B%E8%B7%AF/
 5 EMAIL:y1053419035@qq.com
 6 */
 7 
 8 package main
 9 
10 import (
11     "net/http"
12     "log"
13     "github.com/PuerkitoBio/goquery"
14     "fmt"
15     "errors"
16 )
17 
18 func fetch(url string) ([]string,error) {
19     var urls []string //定義一個空切片數組
20     resp,err := http.Get(url)
21     if err != nil {
22         log.Fatal(err)
23     }
24     defer resp.Body.Close()
25     if resp.StatusCode != http.StatusOK{
26         return nil,errors.New(resp.Status) //表示當出現錯誤是,返回空列表,並將錯誤狀態返回。
27     }
28     doc,err := goquery.NewDocumentFromResponse(resp)
29     if err != nil {
30         log.Fatal(err)
31     }
32     doc.Find("img").Each(func(i int, s  *goquery.Selection) {
33         link,ok := s.Attr("src")
34         if ok {
35             urls = append(urls,link)  //將過濾出來的圖片路徑都追加到urls的數組中去,最終返回給用戶。
36         }else {
37             fmt.Println("抱歉,沒有發現該路徑。")
38         }
39 
40     })
41     return urls,nil
42 }
43 
44 func main() {
45     url := "http://m.xiaohuar.com"  //定義一個URl,也就是咱們要爬的網站。注意這裏不要用www,而要用m,由於m是用手機端方式訪問。而www是電腦方式訪問。
46     urls,err := fetch(url)
47     if err != nil {
48         log.Fatal(err)
49     }
50     for _,u := range urls {
51         fmt.Println(u)
52     }
53 
54 }
 1 [root@yinzhengjie tmp]# more goquery.go 
 2 /*
 3 #!/usr/bin/env gorun
 4 @author :yinzhengjie
 5 Blog:http://www.cnblogs.com/yinzhengjie/tag/GO%E8%AF%AD%E8%A8%80%E7%9A%84%E8%BF%9B%E9%98%B6%E4%B9%8B%E8%B7%AF/
 6 EMAIL:y1053419035@qq.com
 7 */
 8 
 9 package main
10 
11 import (
12         "net/http"
13         "log"
14         "github.com/PuerkitoBio/goquery"
15         "fmt"
16         "errors"
17 )
18 
19 func fetch(url string) ([]string,error) {
20         var urls []string //定義一個空切片數組
21         resp,err := http.Get(url)
22         if err != nil {
23                 log.Fatal(err)
24         }
25         defer resp.Body.Close()
26         if resp.StatusCode != http.StatusOK{
27                 return nil,errors.New(resp.Status) //表示當出現錯誤是,返回空列表,並將錯誤狀態返回。
28         }
29         doc,err := goquery.NewDocumentFromResponse(resp)
30         if err != nil {
31                 log.Fatal(err)
32         }
33         doc.Find("img").Each(func(i int, s  *goquery.Selection) {
34                 link,ok := s.Attr("src")
35                 if ok {
36                         urls = append(urls,link)  //將過濾出來的圖片路徑都追加到urls的數組中去,最終返回給用戶。
37                 }else {
38                         fmt.Println("抱歉,沒有發現該路徑。")
39                 }
40 
41         })
42         return urls,nil
43 }
44 
45 func main() {
46         url := "http://m.xiaohuar.com"  //定義一個URl,也就是咱們要爬的網站。注意這裏不要用www,而要用m,由於m是用手機端方式訪問。而w
47 ww是電腦方式訪問。
48         urls,err := fetch(url)
49         if err != nil {
50                 log.Fatal(err)
51         }
52         for _,u := range urls {
53                 fmt.Println(u)
54         }
55 
56 }
57 
58 [root@yinzhengjie tmp]# 
59 [root@yinzhengjie tmp]# 
60 [root@yinzhengjie tmp]# go run goquery.go 
61 http://www.xiaohuar.com/d/file/20170715/61110ba027f004fb503ff09cdee44d0c.jpg
62 http://www.xiaohuar.com/d/file/20170707/f7ca636f73937e33836e765b7261f036.jpg
63 http://www.xiaohuar.com/d/file/20170701/fb18711a6af87f30942d6a19f6da6b3e.jpg
64 http://www.xiaohuar.com/d/file/20170628/f3d06ef49965aedbe18286a2f221fd9f.jpg
65 http://www.xiaohuar.com/d/file/20170626/0ab1d89f54c90df477a90aa533ceea36.jpg
66 http://www.xiaohuar.com/d/file/20170619/e0456729d4dcbea569a1acbc6a47ab69.jpg
67 http://www.xiaohuar.com/d/file/20170612/1f6620771e2815d21f37d481fa8311e6.png
68 http://www.xiaohuar.com/d/file/20170604/ec3794d0d42b538bf4461a84dac32509.jpg
69 http://www.xiaohuar.com/d/file/20170603/e55f77fb3aa3c7f118a46eeef5c0fbbf.jpg
70 http://www.xiaohuar.com/d/file/20170603/c34b29f68e8f96d44c63fe29bf4a66b8.jpg
71 http://www.xiaohuar.com/d/file/20170529/e5902d4d3e40829f9a0d30f7488eab84.jpg
72 http://www.xiaohuar.com/d/file/20170529/8140c4ad797ca01f5e99d09c82dd8a42.jpg
73 http://www.xiaohuar.com/d/file/20170528/b352258c83776b9a2462277dec375d0c.jpg
74 http://www.xiaohuar.com/d/file/20170527/4a7a7f1e6b69f126292b981c90110d0a.jpg
75 http://www.xiaohuar.com/d/file/20170520/dd21a21751e24a8f161792b66011688c.jpg
76 http://www.xiaohuar.com/d/file/20170516/6e295fe48c33245be858c40d37fb5ee6.jpg
77 http://www.xiaohuar.com/d/file/20170513/6121e3e90ff3ba4c9398121bda1dd582.jpg
78 http://www.xiaohuar.com/d/file/20170512/45fc9ed5d92c66f369b66841c58bd183.jpg
79 [root@yinzhengjie tmp]# 
以上代碼執行結果戳這裏喲

 

擴展:

  咱們在訪問一個標籤中的源數據,可能獲取的路徑不是完整路徑,那麼如何將獲取的路徑補充其應該對應的絕對路徑呢?咱們能夠簡單來實現一下,後期咱們能夠對其作一個優化。

 1 /*
 2 #!/usr/bin/env gorun
 3 @author :yinzhengjie
 4 Blog:http://www.cnblogs.com/yinzhengjie/tag/GO%E8%AF%AD%E8%A8%80%E7%9A%84%E8%BF%9B%E9%98%B6%E4%B9%8B%E8%B7%AF/
 5 EMAIL:y1053419035@qq.com
 6 */
 7 
 8 package main
 9 
10 import (
11     "errors"
12     "fmt"
13     "github.com/PuerkitoBio/goquery"
14     "log"
15     "net/http"
16     "net/url"
17     "os"
18     "strings"
19 )
20 
21 func fetch(url string) ([]string, error) { //改函數會拿到咱們想要的圖片的路徑。
22     var urls []string //定義一個空切片數組
23     resp, err := http.Get(url)
24     if err != nil {
25         log.Fatal(err)
26     }
27     defer resp.Body.Close()
28     if resp.StatusCode != http.StatusOK {
29         return nil, errors.New(resp.Status) //表示當出現錯誤是,返回空列表,並將錯誤狀態返回。
30     }
31     doc, err := goquery.NewDocumentFromResponse(resp)
32     if err != nil {
33         log.Fatal(err)
34     }
35     doc.Find("img").Each(func(i int, s *goquery.Selection) {
36         link, ok := s.Attr("src")
37         if ok {
38             urls = append(urls, link) //將過濾出來的圖片路徑都追加到urls的數組中去,最終返回給用戶。
39         } else {
40             fmt.Println("抱歉,沒有發現該路徑。")
41         }
42 
43     })
44     return urls, nil
45 }
46 
47 func Clean_urls(root_path string, picture_path []string) []string {
48     var Absolute_path []string //定義一個絕對路徑數組。
49     url_info, err := url.Parse(root_path)
50     if err != nil {
51         log.Fatal(err)
52     }
53     Scheme := url_info.Scheme //獲取到連接的協議
54     //fmt.Println("使用的協議是:",Scheme)
55     Host := url_info.Host //獲取連接的主機名
56     //fmt.Println("主機名稱是:",Host)
57     Path := url_info.Path                         //獲取到連接的相對路徑
58     Path_Directory := strings.Split(Path, "/")[1] //獲取到存放文件的目錄的路徑「Path_Directory」。
59     //fmt.Println("存放文件的目錄是:",Path_Directory)
60     for _, souce_path := range picture_path {
61         if strings.HasPrefix(souce_path, "https") { //若是當前當前路徑是以「https」開頭說明是絕對路徑,所以咱們給一行空代碼,表示不執行任何操做,千萬別寫:「continue」,空着就好。
62 
63         } else if strings.HasPrefix(souce_path, "//") { //判斷當前路徑是否以「//」開頭(說明包含主機名)
64             souce_path = Scheme + ":" + souce_path //若是是就對其進行拼接操做。如下邏輯相同。
65         } else if strings.HasPrefix(souce_path, "/") { //說明不包含主機名和協議,咱們進行拼接便可。
66             souce_path = Scheme + "://" + Host + souce_path
67         } else {
68             souce_path = Scheme + "://" + Host + "/" + Path_Directory + "/" + souce_path
69         }
70         Absolute_path = append(Absolute_path, souce_path) //無論是否知足上面的條件,最終都會被追加到該數組中來。
71     }
72     return Absolute_path //最終返回處理後的每一個連接的絕對路基。
73 }
74 
75 func main() {
76     root_path := os.Args[1]               //定義一個URl,也就是咱們要爬的網站。
77     picture_path, err := fetch(root_path) //「fetch」函數會幫咱們拿到picture_path的路徑,可是路徑多是相對路徑或是絕對路徑。不一樣意。
78     if err != nil {
79         log.Fatal(err)
80     }
81 
82     Absolute_path := Clean_urls(root_path, picture_path) //「Clean_urls」函數會幫咱們把picture_path的路徑作一個統一,最終都拿到了絕對路徑Absolute_path數組。
83 
84     for _, Picture_absolute_path := range Absolute_path {
85         fmt.Println(Picture_absolute_path) //最終咱們會獲得一個圖片的完整路徑,咱們能夠對這個路徑進行下載,壓縮,加密等等操做。
86     }
87 }
相關文章
相關標籤/搜索