Giter Club home page Giter Club logo

google-parser's Introduction

Hi there ๐Ÿ‘‹

I am Yoann, a French web developer and music composer living in Bangkok, Thailand.

๐Ÿš€ Projects

  • Founded Jarvis, an AI-powered app that generates lyrics ideas to help songwriters overcome writer's block.
  • Launched BeatHub, a web app to help music producers dig sample packs and beats more efficiently by providing a random and continuous listening experience.

๐Ÿคน Skills

google-parser's People

Contributors

dependabot[bot] avatar ynnsnr avatar

Watchers

 avatar

google-parser's Issues

Code cleanup

Remove all un-used generated files e.g. helpers

GoogleScraper class architecture

The current implementation of GoogleScraper is quite raw and could be improved:

  • Not using class accessors
  • Methods are super long so hard to read and maintain over time

Something like that would have been more satisfying:

class GoogleScraper
  def initialize
    @driver = selenium_driver
  end

  def scrape(keyword)
    search(keyword)

    {
      raw_html: driver.page_source,
      links_count: scraped_links_count,
      adwords_advertiser_count: scraped_ads_count,
      results_count: scraped_results_count
    }
  end

  def quit
    @driver.quit
  end

  private

  attr_reader :driver

  def selenium_driver
    Selenium::WebDriver.for :chrome,
                            options: selenium_options,
                            desired_capabilities: driver_capabilities
  end

  def driver_options
    options = Selenium::WebDriver::Chrome::Options.new
    options.add_argument('--ignore-certificate-errors')
    options.add_argument('--disable-popup-blocking')
    options.add_argument('--disable-translate')
    options.add_argument('--no-sandbox')
    options.add_argument('--disable-extensions')
    options.add_argument('--window-size=800,600')
    options.add_argument('--headless')
    options
  end

  def driver_capabilities
    Selenium::WebDriver::Remote::Capabilities.chrome
  end

  def search(keyword)
    driver.navigate.to('https://www.google.com/?hl=en')
    driver.find_element(name: 'q').send_keys(keyword)
    driver.find_element(name: 'q').send_keys(:return)
  end

  def scraped_links_count
    driver.find_elements(tag_name: 'a').count
  end

  def scraped_results_count
    driver.find_element(id: 'resultStats')
          .text
          .match(/(?<count>[\d,]+) results/)[:count]
          .delete(',')
          .to_i
  end

  def scraped_ads_count
    driver.find_elements(class_name: 'ads-ad').count + driver.find_elements(class_name: 'pla-unit').count
  end
end

GoogleScraper tests are too simplistic

The tests do not cover the basic functionality which is to extract date from an HTML page.

It does not need to be complicated as using a stubbed response for Selenium::WebDriver::Remote would work (i.e. using a stored HTML response in spec/fixtures)

Overall the tests coverage is way too low.

Keep all test configuration in `spec/support`

Prefer keeping ActiveJob::Base.queue_adapter = :test in the support subdirectory as it would applu to all tests.

#spec/support/activejob.rb

ActiveJob::Base.queue_adapter = :test

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.