logo
Loading...

找不到用scrapy產生的json檔 - Cupoy

老師您好:照著老師提供的D27 & D28 的範例去實作利用scrapy去抓取檔案並且產生json,...

pycrawler-2

找不到用scrapy產生的json檔

2020/03/29 上午 07:10
Python網路爬蟲討論版
黃琳芹
觀看數:11
回答數:2
收藏數:0
pycrawler-2

老師您好:

照著老師提供的D27 & D28 的範例去實作利用scrapy去抓取檔案並且產生json,可是在專案資料夾中卻完全找不到該json檔案,請問究竟是存到哪裡去了呢?

回答列表

  • 2020/03/29 上午 07:43
    黃琳芹
    贊同數:0
    不贊同數:0
    留言數:0

    不好意思,我自己發現問題在哪了,要在setting檔案中將pipeline指向到自己建立的JSONPipeline class才能順利處理。不過,在後面的數字究竟是什麼意思呢?我看了該網站的說明,還是不太明白是什麼意思。

  • 2020/03/29 下午 08:38
    張維元 (WeiYuan)
    贊同數:0
    不贊同數:0
    留言數:0

    嗨,琳芹


    這是一個好問題,我們可以先看一下官方文件的描述:


    ```

    After an item has been scraped by a spider, it is sent to the Item Pipeline which processes it through several components that are executed sequentially.


    Each item pipeline component (sometimes referred as just “Item Pipeline”) is a Python class that implements a simple method. They receive an item and perform an action over it, also deciding if the item should continue through the pipeline or be dropped and no longer processed.

    ```


    這裡可以把 Item Pipeline 想像成是一個工作,例如「取資料」、「清理資料」、「儲存資料」這樣都算是不同的 task,所以一個爬蟲是由很多的 task 依序執行來實現的。這裡的數字的代表的是執行的優先順序,數值越大越先執行。一樣可以看一下文件的說明:


    ```

    The integer values you assign to classes in this setting determine the order in which they run: items go through from lower valued to higher valued classes. It’s customary to define these numbers in the 0-1000 range.

    ```


    如果這個回答對你有幫助請主動點選「有幫助」的按鈕,也可以追蹤我的GITHUB帳號。若還有問題的話,也歡迎繼續再追問或者把你理解的部分整理上來,我都會提供你 Review 和 Feedback 😃😃😃