Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Web Scraping for Fun and Profit using Scrapy

Avatar for Sigit Dewanto Sigit Dewanto
November 26, 2016

Web Scraping for Fun and Profit using Scrapy

Avatar for Sigit Dewanto

Sigit Dewanto

November 26, 2016

Other Decks in Technology

Transcript

  1. Tentang Saya • Software engineer di Scrapinghub (2014 - ?)

    ◦ Scrapinghub adalah Scrapy official maintainer • Sebelumnya Java dev di Wego.com, tim FPI ◦ Wego adalah travel meta-search engine
  2. Web Crawling • Bagaimana mendapatkan halaman web yang kita inginkan?

    • Yang kita butuhkan: HTTP Client ◦ Requests (Kenneth Reitz) ◦ Twisted web client
  3. Web Scraping • Kita sudah mendapatkan halaman web-nya. • Bagaimana

    mengekstrak data dari halaman web tersebut? • Yang kita butuhkan: ◦ HTML/XML parser: lxml, (Beautiful Soup) ◦ JSON parser: json, demjson ◦ Javascript parser: js2xml ◦ PDF: pdfquery
  4. 2. Definisikan skema data from scrapy import Item, Field class

    ProductItem(Item): sku = Field() name = Field() price = Field()
  5. 3. Buat spider • Inspeksi sampel halaman web ◦ Firebug,

    Google Developer Tools ◦ scrapy shell • CSS Selector, XPath • Regular Expression (regex) ◦ When we need to extract part of string
  6. Scrapinghub Cloud • Dash: web dashboard • shub: command line

    tool untuk deployment • scrapinghub: wrapper untuk Scrapinghub API
  7. Terima Kasih! • Source code ◦ https://github.com/seagatesoft/scrapydemo • Tertarik menggunakan

    Scrapinghub cloud? ◦ https://app.scrapinghub.com/account/signup/
  8. Etika/Kesopanan • Crawl rate ◦ Jeda antara HTTP request ◦

    Batasi concurrent requests • Patuhi robots.txt • Identifikasi crawler Anda dengan User-Agent header
  9. Aspek Legal “It’s not scraping itself which is good or

    bad, or legal or illegal, but the circumstances in which you’re doing it.” Francis Irving - ScraperWiki (https://blog.scraperwiki.com/2012/04/is-scraping-legal/ )
  10. Common issues • HTML page manipulated by Javascript • Antibot

    measurements ◦ Bot detection + ban ◦ Spider trap ◦ CAPTCHA • Huge number of links/pages • Irregular structure (no pattern)