恆鼎爬蟲外包專案

目錄

  • 爬蟲原理簡介
  • 環境部署
  • 程式碼導讀
  • 工作流程
  • 出作業(・ω・)

網路概論

使用者

伺服器

請求(GET、POST、DELETE......)

回應(HTML、JSON、text......)

用 DOM 處理 HTML 檔

DOM

  • 一種將 HTML 文檔具象成樹狀資料結構的模型
  • 操作這種模型的選擇器(Selector)有很多
    • XPath
    • CSS Selector
    • ...
<html>
    <head>
    </head>
    <body>
        <h1> Hello World! </h1>
        <p> Hello どうも ぼく は ここ </p>
    </body>
</html>

<html>

<head>

<body>

<h1>

<p>

我是 CSS Selector 派

CSS Selector

CSS Selector

選取單一標籤

<html>
    <head>
    </head>
    <body>
        <h1> Hello World! </h1>
        <p> Hello どうも ぼく は ここ </p>
        <a href="https://lili668668.github.io">私 は ballfish です</a>
    </body>
</html>
h1

選取帶 class 的標籤

<html>
    <head>
    </head>
    <body>
        <h1> Hello World! </h1>
        <h1 class="ha owo"> Hello World! with class two </h1>
        <h1 class="ha"> Hello World! with class ha </h1>
        <h1 class="owo"> Hello World! with class owo </h1>
        <p> Hello どうも ぼく は ここ </p>
        <a href="https://lili668668.github.io">私 は ballfish です</a>
    </body>
</html>
h1.owo

選取帶 id 的標籤

<html>
    <head>
    </head>
    <body>
        <h1> Hello World! </h1>
        <h1 class="ha owo"> Hello World! with class two </h1>
        <h1 class="ha"> Hello World! with class ha </h1>
        <h1 class="owo"> Hello World! with class owo </h1>
        <p id="here"> Hello どうも ぼく は ここ </p>
        <p id="there"> Hello どうも ぼく は そこ </p>
        <a href="https://lili668668.github.io">私 は ballfish です</a>
    </body>
</html>
p#there

選取子孫標籤

<html>
    <head>
    </head>
    <body>
        <h1 id="OAO">
            <a href="https://google.com">I'm here</a>
            <p>, Not <a href="http://yahoo.com.tw">there</a> </p>
            <p>, Also Not <a href="http://github.com">there</a> </p>
        </h1>
    </body>
</html>
h1#OAO a

選取子標籤

<html>
    <head>
    </head>
    <body>
        <h1 id="OAO">
            <a href="https://google.com">I'm here</a>
            <p>, Not <a href="http://yahoo.com.tw">there</a> </p>
            <p>, Also Not <a href="http://github.com">there</a> </p>
        </h1>
    </body>
</html>
h1#OAO > a

選取第二個子標籤

<html>
    <head>
    </head>
    <body>
        <h1 id="OAO">
            <a href="https://google.com">I'm here</a>
            <p>, Not <a href="http://yahoo.com.tw">there</a> </p>
            <p>, Also Not <a href="http://github.com">there</a> </p>
        </h1>
    </body>
</html>
h1#OAO > p:nth-child(2) > a

大致上這樣

其它的可以去玩遊戲,學更多(・ω・)

http://toolness.github.io/css-selector-game/

https://flukeout.github.io/

或看文件(・∀・)

https://developer.mozilla.org/zh-TW/docs/Web/CSS/CSS_Selectors

套件簡介

使用的套件

自己寫的模組

  • Tools
    • Downloader
      • Get(string url, Encoding) : string html
      • Post(string url, Dictionary<string, string> param, Encoding encoding) : string html
    • Tools
      • FilterHtml(string html) : string clean_html

Data

  • Url: 文章網址
  • PostID: 文章 ID
  • PostTitle: 文章標題
  • PostCreateDate: 文章發表時間
  • PostContent: 文章內容
  • AuthorName: 作者名字,如果沒有,寫網站名字
  • AuthorID: 作者ID,如果沒有,與 AuthorName 一樣
  • AuthorUrl: 作者 Url ,如果沒有,寫網站的首頁

參考的程式碼

  • BuzzOrange
  • Cardu

有問題的話

  1. 約時間出來
  2. 來公司找我
    1. 星期一
    2. 星期四下午
    3. 星期五上午
  3. TeamViewer ,遠端詢問
  4. 訊息問我
    1. 傳程式檔案給我
    2. 節圖標示問題點
    3. 來龍去脈說清楚

出作業

(・ω・)

  • 這裡,選一個你要爬的
  • 在 12/04 之前,寫完傳程式碼(壓縮檔)給我
  • 可以提早繳交,死線之前做不完要說
  • 然後來約個下次的時間吧 (・∀・)

恆鼎爬蟲外包

By 球魚

恆鼎爬蟲外包

恆鼎爬蟲外包,簡介簡報

  • 769