<commit_before>require "gsearch-parser/version"
require 'open-uri'
require 'nokogiri'

module GSearchParser

  def GSearchParser.webSearch(query)
    GoogleSearch.new(query)
  end

end

###################################################
#                                                 #
#              GoogleSearch Class                 #
#                                                 #
###################################################
class GoogleSearch
  attr_accessor :results

  # Class initializer
  def initialize(query)
    # Initialize array
    @results = Array.new

    # TODO: Format query

    # Fetch page
    searchPage = Nokogiri::HTML(open("http://google.com/search?sourceid=chrome&q=#{query}", 
      'User-Agent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.152 Safari/535.19'))

    # Iterate over each Google result list element and extract data
    searchPage.css('li.g').each do |result|
      title = result.css('h3').first.content
      content = result.css('span.st').first.inner_html
      uri = result.css('cite').inner_html
      @results << Result.new(title, content, uri)
    end
  end

  # Iterator over results
  def each(&blk)
    @results.each(&blk)
  end

  ###################################################
  #                                                 #
  #                Result Class                     #
  #                                                 #
  ###################################################
  class Result
    attr_accessor :title, :content, :uri

    # Class initializer
    def initialize(title, content, uri)
      @title = title
      @content = content
      @uri = uri<commit_msg>Removed bug caused by trying to access inner html.<commit_after>require "gsearch-parser/version"
require 'open-uri'
require 'nokogiri'

module GSearchParser

  def GSearchParser.webSearch(query)
    GoogleSearch.new(query)
  end

end

###################################################
#                                                 #
#              GoogleSearch Class                 #
#                                                 #
###################################################
class GoogleSearch
  attr_accessor :results

  # Class initializer
  def initialize(query)
    # Initialize array
    @results = Array.new

    # TODO: Format query

    # Fetch page
    searchPage = Nokogiri::HTML(open("http://google.com/search?sourceid=chrome&q=#{query}", 
      'User-Agent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.152 Safari/535.19'))

    # Iterate over each Google result list element and extract data
    searchPage.css('li.g').each do |result|
      title = result.css('h3').first.content
      content = result.css('span.st').first
      uri = result.css('cite')
      @results << Result.new(title, content, uri)
    end
  end

  # Iterator over results
  def each(&blk)
    @results.each(&blk)
  end

  ###################################################
  #                                                 #
  #                Result Class                     #
  #                                                 #
  ###################################################
  class Result
    attr_accessor :title, :content, :uri

    # Class initializer
    def initialize(title, content, uri)
      @title = title
      @content = content
      @uri = uri
{'fraction_non_alphanumeric': 0.20730646564221514, 'fraction_numerical': 0.015656712090461003, 'mean_word_length': 2.0369718309859155, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '76266', 'n_tokens_mistral': 923, 'n_tokens_neox': 860, 'n_words': 203}