COSCUP
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee
  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    Web Scrapping, Crawler and PHP - 李昀陞 === ###### tags: `COSCUP2020` `中階` `RB105` {%hackmd 7CD4pdKQTa2p6Y3VqH3VrQ %} > 請從這裡開始 http://slides.com/peter279k/web-scrapping-crawler-and-php ## About me * 開源專案貢獻者 * 現任職於工研院 * PHP 5.3~7+ ## Jokes about web crawler and php > 為什麼 Python 爬蟲相關的書那麼多,PHP 卻只有一本? ## My small story about learning web crawler * 《Webbots, crawlers, and screen scrapers》 * 作者有回信 ## My first web crawler 校園 Wi-Fi 自動驗證 ## Screen scrapers... ## iMacros * 用腳本操控Web瀏覽器 * 商用授權,後來就沒聽到人使用了 ## First hackathon in 2015 * 自動爬取學校新聞爬蟲 ## Back nowadays ## Fundameals * Web Bot * Web Crawler * Web Scraping ## Develop your first web crawler ### Environment * Linux(Especially Ubuntu 16.04+ * Google Chrome * PHP * ... ### Installation * 安裝 Composer * guzzle * symfony/dom-crawler * symfony/css-selector * 或是用打包好的 Docker (待補) ## Inspection ### Target URL ### Latest News URL ### HTTP inspection * 頁面自動載入 * Chrome 瀏覽器的開發者工具列可以看載入頁面的請求 header, Centent-Type 為 text/html * 開啟 Response 分頁結果內容是 json ## Organize thoughts 1. 請求網址 2. 發送請求Two 3. 解析 a tag 得出下一頁的網址 4. 最後會得到一個關聯式陣列 ## DOM Tree * 取得底下某個 tag 的相關資訊 ## Basic Case Study ### Target URL for iframe * 台電備轉容量 * Intern: I cannot find these data sets * 圖表是一個 iframe 的獨立頁面 * 載入 3 個 CSV 檔(107~109 民國年) ## Advanced/Useful ... ### Subject System: ASP.NET * 最難爬取 * 選課系統 * 奇怪的 hidden value ### Invalid User Agent ### Subject System Crawling * Request Header 帶過去 * Cookie 設好 ### Invalid Order Form Params * 參數順序錯就會觸發 Invalid ViewState 錯誤 ## Javascript * 在瀏覽器前端做一些處理 ## Web Page loading * Open Web browser and type URL * Web page loading * DOM ready * DOMContentLoaded * * Execute JS * Page Ready ## Web Page loading for Web Driver/Engine * Selenium * headless chrome * peppeteer * 簡化 headless chrome 操作 * PhantomJS(現已不再維護) ## headless chrome chome-php/chrome php 套件 ## Case Study ### 某廣播網站 * 節目頁面內容全部載入 json ,假的載入更多實現 * 播放頁面音檔 key 放在 local storage * json string 的 json string(!) * 使用 headless Chrome 執行 javascript 取得需要的東西 ## Anti Crawler / Anti-Bot * 用 sleep 來模擬人類操作迴避 ## Are you afraid of Captcha * 假的驗證碼 * 圖片驗證碼 * 用 OCR 解決(Tesseract) ## Organize Thoughts ... ## Command Wrapper Tesseract in PHP Tesseract OCR for PHP ## More funny captchas funny-captcha.md ## 總結 * 寫給 PHP 開發者的 30 堂網路爬蟲開發 * 有趣驗證碼的分析 * Tesseract * ~~通靈~~ ## Q&A

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully