owned this note changed 4 years ago
Linked with GitHub

爬蟲與反爬蟲乾貨 - 蔡根元

歡迎來到 PyCon TW 2021 共筆

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

共筆入口:https://hackmd.io/@pycontw/2021
手機版請點選上方 按鈕展開議程列表。
Welcome to PyCon TW 2021 Collaborative Writing
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Collaborative Writing Workplace:https://hackmd.io/@pycontw/2021
Using mobile please tap to unfold the agenda.

從這開始共筆

投影片連結

爬蟲起手式

  • 直接從要爬資料的網頁開始,避免前面不必要的頁面跳轉
  • xpath 可以解決幾乎所有動態的問題
  • requests 效率相對比較好,因為少 load 一些圖片等資料
  • 如果遇到網站阻擋,最好繞開不要和網站硬碰硬
  • 登入
    • 如果能用 requests 直接登入,就使用同一個 session 繼續操作即可
    • 如果不行,就先使用 selenuim 登入之後,再用 requests 操作

進階方法破解登入、驗證碼、語音驗證碼

Chrome Options 奇怪的用法

特殊案例分享

開發以外的事情

結論

  • 爬蟲

    • selenium 萬用、門檻低
    • requests 效率
    • 注意禮貌,不要把網站弄壞
    • 推薦 locust 測試網站極限
  • 反爬蟲

    白話文:製造障礙 (注意製造障礙同時不要影響到使用者體驗)

    • 選圖片
    • 驗證碼
    • 不要用文字呈現,改用圖片或 PDF 顯示
    • 登入才能查詢或是擋 cookie 與 header
    • 查詢與取得結果異步,e.g. 查詢後在隨機時間後到另一頁面取得結果
    • 隨機問註冊時的問題
    • 動態 html xpath / ID、name / tag name
    • 阻斷
      • GA 或 log 觀察流量
      • Ban IP
    • 建議
      • 將常被爬的網站轉成open API (爬蟲者好爬,業者可更易觀察到網站上非機器人的流量)
      • xpath中新增DIV,不影響使用者體驗下還能反爬蟲

Q & A

放送事故QQ
歡迎大家直接到 R2 交流區和講者交流

  • 有沒有建議解 5 秒盾的方法

  • 剛剛分享的 Keras 訓練是用什麼模型

  • 請問 google 驗證碼 或 像 binance.com 要手滑過去驗證碼,有辦法破嗎?

    • google recapcha
    • 目前拼拼圖驗證碼還沒找到比較好的方法,請求分享XD
  • 想請問講者,最近想做蝦皮相關需要自動登入,Try過了Header\Delay\referrer或是使用第三方登入的方式但每次都會被擋驗證,想請問講者能提供一下破解(不被偵測到)的思路嗎?

    • 請將問題的相關資訊寄給講者,講者會再研究一下(信箱在投影片第一頁的 QRCode)
    • 建議可以直接把網址或程式,幫助講者更快找到問題XD
tags: PyConTW2021
Select a repo