$30 off During Our Annual Pro Sale. View Details »

ruby conf tw 2012 build your own web scrapper

Dale Ma
December 08, 2012

ruby conf tw 2012 build your own web scrapper

build your own web scrapper

Dale Ma

December 08, 2012
Tweet

Other Decks in Programming

Transcript

  1. Build Your Own Web
    Scraper
    - Dale Ma
    @eguitarz
    12年12月8日星期六

    View Slide

  2. @eguitarz
    It’s fun to do something small and
    easy.
    12年12月8日星期六

    View Slide

  3. @eguitarz
    I always want to build a robot to
    serve me.
    12年12月8日星期六

    View Slide

  4. @eguitarz
    Since making a robot is too difficult,
    so I choose to make a web bot.
    12年12月8日星期六

    View Slide

  5. @eguitarz
    Today I’m talking about how do I
    build my own web scraper in ruby.
    12年12月8日星期六

    View Slide

  6. @eguitarz
    Web scrapers have many uses. For
    example...
    12年12月8日星期六

    View Slide

  7. @eguitarz
    Up time survey, image collecting,
    automate web snapshots and more...
    12年12月8日星期六

    View Slide

  8. @eguitarz
    Usually, there are many scrapers
    (threads) fired at the same time.
    12年12月8日星期六

    View Slide

  9. @eguitarz
    So, first things first, I have to control
    the threads.
    12年12月8日星期六

    View Slide

  10. @eguitarz
    I decide to write #threadpool to do
    this such thing.
    12年12月8日星期六

    View Slide

  11. @eguitarz
    You can find that at https://
    github.com/eguitarz/threadpool
    12年12月8日星期六

    View Slide

  12. @eguitarz
    Threadpool decides the life of each
    thread.
    12年12月8日星期六

    View Slide

  13. @eguitarz
    Now, let’s go for the main dish.
    12年12月8日星期六

    View Slide

  14. @eguitarz
    Web scrappers should be able to
    `grab page` and `parse html tags`.
    12年12月8日星期六

    View Slide

  15. @eguitarz
    #Nokogiri is good at those things.
    12年12月8日星期六

    View Slide

  16. @eguitarz
    I use “Hash” to save parsed links.
    12年12月8日星期六

    View Slide

  17. @eguitarz
    There’s a problem, links stored in
    hash by threads. But hash in ruby is
    not thread-safe...
    12年12月8日星期六

    View Slide

  18. @eguitarz
    #hamster helps me with this.
    12年12月8日星期六

    View Slide

  19. @eguitarz
    I use `Depth-Limited Search`
    algorithm for my scrapper.
    3 2
    1
    1
    12年12月8日星期六

    View Slide

  20. @eguitarz
    What if the page needs javascript to
    render?
    12年12月8日星期六

    View Slide

  21. @eguitarz
    There’s a easy way... use browser to
    render the html with javascript.
    12年12月8日星期六

    View Slide

  22. @eguitarz
    How?
    12年12月8日星期六

    View Slide

  23. @eguitarz
    #Waltir or #Selenium
    12年12月8日星期六

    View Slide

  24. Gonna show my little toy...
    12年12月8日星期六

    View Slide

  25. @eguitarz
    My scraper is on github at https://
    github.com/eguitarz/macaron
    12年12月8日星期六

    View Slide

  26. @eguitarz
    The demo is simple, `you` can
    enhance or create new one.
    12年12月8日星期六

    View Slide

  27. @eguitarz
    Wikipedia scraper, Facebook
    scraper... could be interesting!
    12年12月8日星期六

    View Slide

  28. THANKS!
    12年12月8日星期六

    View Slide