steam_scraper 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 129284f963ebd372b9afba769e1da4dc4e541f33
4
+ data.tar.gz: 1da952ef7ac1b425d837d79cac0a14cfcff76695
5
+ SHA512:
6
+ metadata.gz: ce43a448f7707cfb5036b4815d7f4c66d19e5561aa65d4bfb8a302337ae20612083ee65a87d6828d931028168ca3dfcd8374f1f0b6ca6cf072ca0917b1648a37
7
+ data.tar.gz: 230a3c1e53a67efc3e6476e25b2807c88e6d7ec1f0f498089e9c0feccdfc83caef79e6c4153785ae73dca6fd56dd301eee330ca5412de889adcf2da33c51b14e
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,11 @@
1
+ Style/IfUnlessModifier:
2
+ MaxLineLength: 120
3
+
4
+ Style/WhileUntilModifier:
5
+ MaxLineLength: 120
6
+
7
+ Metrics/LineLength:
8
+ Max: 120
9
+
10
+ Metrics/AbcSize:
11
+ Max: 99999
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in steam_scraper.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Robert Gardner
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # SteamScraper
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'steam_scraper'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install steam_scraper
18
+
19
+ ## Usage
20
+
21
+ To scrape all pages from the steam store:
22
+
23
+ ```Ruby
24
+ scraper = SteamScraper.new
25
+ results = scraper.scrape
26
+ ```
27
+
28
+ To scrape a range of pages from the steam store:
29
+
30
+ ```Ruby
31
+ scraper = SteamScraper.new
32
+ results = scraper.scrape(first_page, last_page)
33
+ ```
34
+
35
+
36
+ ## Development
37
+
38
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
39
+
40
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
41
+
42
+ ## Contributing
43
+
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ShriekBob/steam_scraper.
45
+
46
+
47
+ ## License
48
+
49
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'steam_scraper'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ require 'pry'
11
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,116 @@
1
+ require_relative './page_retriever.rb'
2
+
3
+ # Core scraping class
4
+ class GameListScraper
5
+ def initialize(*_args)
6
+ @game_list = []
7
+ @page_retriever = PageRetriever.new
8
+ current_page_contents = get_page_contents(site + 1.to_s)
9
+ pagination_contents = current_page_contents.xpath("//div[contains(@class, 'search_pagination_right')]") .text
10
+ last_page_number = pagination_contents.scan(/(\d+)/i) .flatten.last
11
+ @last_page_num = last_page_number.to_i
12
+ end
13
+
14
+ def site
15
+ 'http://store.steampowered.com/search?page='
16
+ end
17
+
18
+ def get_page_contents(url)
19
+ @page_retriever.retrieve(url)
20
+ end
21
+
22
+ def search_results(page_number)
23
+ current_page_contents = get_page_contents(site + page_number.to_s)
24
+ current_page_contents.xpath("//div[@id='search_result_container']/div/a")
25
+ end
26
+
27
+ def scrape(first_page = 1, last_page = nil)
28
+ last_page ||= @last_page_num
29
+ # scrape each search page
30
+ puts 'Scraping Steam Store pages ' + [first_page..last_page].join(' to ')
31
+ (first_page..last_page).each do |page|
32
+ puts 'Scraping Page ' + page.to_s
33
+ items_on_page = search_results(site + page.to_s)
34
+ scrape_page(items_on_page)
35
+ puts 'Page Complete'
36
+ end
37
+ puts 'Scraping Complete'
38
+ @game_list
39
+ end
40
+
41
+ def scrape_page(current_page)
42
+ current_page.each do |entry|
43
+ scrape_entry(entry)
44
+ end
45
+ end
46
+
47
+ def scrape_url(entry)
48
+ entry.attribute('href').value
49
+ end
50
+
51
+ def scrape_name(entry)
52
+ entry.xpath(".//span[@class='title']").text
53
+ end
54
+
55
+ def scrape_price(entry)
56
+ entry.xpath(".//div[contains(@class, 'search_price')
57
+ and not(contains(@class, 'search_price_discount_combined'))]")
58
+ .text
59
+ .strip
60
+ .split('$')
61
+ .last
62
+ end
63
+
64
+ def scrape_release_date(entry)
65
+ Date.parse(entry.xpath(".//div[contains(@class, 'search_released')]").text)
66
+ end
67
+
68
+ def scrape_platforms(entry)
69
+ platforms = []
70
+ platforms.push('Windows') unless entry.xpath(".//span[contains(@class, 'win')]").empty?
71
+ platforms.push('macOS') unless entry.xpath(".//span[contains(@class, 'mac')]").empty?
72
+ platforms.push('Linux') unless entry.xpath(".//span[contains(@class, 'linux')]").empty?
73
+ platforms.push('Steamplay') unless entry.xpath(".//span[contains(@class, 'steamplay')]").empty?
74
+
75
+ platforms
76
+ end
77
+
78
+ def scrape_icon_url(entry)
79
+ entry.xpath(".//div[contains(@class, 'search_capsule')]/img").attribute('src').value
80
+ end
81
+
82
+ def get_review_contents(entry)
83
+ entry.xpath(".//span[contains(@class, 'search_review_summary')]")
84
+ .attribute('data-store-tooltip')
85
+ .value
86
+ end
87
+
88
+ def scrape_review_score(entry)
89
+ review_string = get_review_contents(entry)
90
+ matches = /.*(\d\d)[%]/i.match(review_string)
91
+ review_percentage = matches[1] unless matches.nil?
92
+
93
+ review_percentage
94
+ end
95
+
96
+ def scrape_number_of_reviews(entry)
97
+ review_string = get_review_contents(entry)
98
+ matches = /.*\d\d[%] of the ([0-9,]*) user/i.match(review_string)
99
+ num_reviews = matches[1] unless matches.nil?
100
+
101
+ num_reviews
102
+ end
103
+
104
+ def scrape_entry(entry)
105
+ new_game = {}
106
+ new_game[:url] = scrape_url(entry)
107
+ new_game[:name] = scrape_name(entry)
108
+ new_game[:price] = scrape_price(entry)
109
+ new_game[:release_date] = scrape_release_date(entry)
110
+ new_game[:platforms] = scrape_platforms(entry)
111
+ new_game[:icon_url] = scrape_icon_url(entry)
112
+ new_game[:review_score] = scrape_review_score(entry)
113
+ new_game[:number_of_reviews] = scrape_number_of_reviews(entry)
114
+ @game_list.push new_game
115
+ end
116
+ end
@@ -0,0 +1,91 @@
1
+ require_relative './page_retriever.rb'
2
+
3
+ # Class that scrapes a games actual page
4
+ class GamePageScraper
5
+ def initialize(*_args)
6
+ @page_retriever = PageRetriever.new
7
+ end
8
+
9
+ def scrape(games_hash)
10
+ games_hash.map! do |game|
11
+ url = game[:url]
12
+ scrape_game!(game, url) unless url.nil?
13
+ end
14
+ games_hash
15
+ end
16
+
17
+ def scrape_game!(game, url)
18
+ puts 'Scraping Page for ' + game[:name]
19
+ page_contents = get_page_contents(url)
20
+ game[:metacritic] = scrape_metacritic(page_contents)
21
+ game[:tags] = scrape_tags(page_contents)
22
+ game[:genres] = scrape_genres(page_contents)
23
+ game[:developer] = scrape_developer(page_contents)
24
+ game[:publisher] = scrape_publisher(page_contents)
25
+ game[:min_spec] = scrape_min_spec(page_contents)
26
+ game[:recommended_spec] = scrape_recommended_spec(page_contents)
27
+
28
+ game
29
+ end
30
+
31
+ def get_page_contents(url)
32
+ @page_retriever.retrieve(url)
33
+ end
34
+
35
+ def scrape_metacritic(page_contents)
36
+ score_element = page_contents.xpath("//div[@id='game_area_metascore']/span").first
37
+ score_element.text.to_i unless score_element.nil?
38
+ end
39
+
40
+ def scrape_tags(page_contents)
41
+ tags = []
42
+ page_contents.xpath("//div[contains(@class, 'popular_tags')]/a").each do |tag|
43
+ tags.push(tag.text.strip)
44
+ end
45
+
46
+ tags
47
+ end
48
+
49
+ def scrape_genres(page_contents)
50
+ genres = []
51
+ details = page_contents.xpath("//div[@class='details_block']")
52
+ details.xpath(".//a[contains(@href, 'genre')]").each do |genre|
53
+ genres.push(genre.text.strip)
54
+ end
55
+
56
+ genres
57
+ end
58
+
59
+ def scrape_developer(page_contents)
60
+ details = page_contents.xpath("//div[@class='details_block']")
61
+ details.xpath(".//a[contains(@href, 'developer')]").text.strip
62
+ end
63
+
64
+ def scrape_publisher(page_contents)
65
+ details = page_contents.xpath("//div[@class='details_block']")
66
+ details.xpath(".//a[contains(@href, 'publisher')]").text.strip
67
+ end
68
+
69
+ def scrape_min_spec(page_contents)
70
+ spec_block = page_contents.xpath("//div[@data-os='win']/div[@class='game_area_sys_req_leftCol']/ul/ul")
71
+ scrape_spec(spec_block)
72
+ end
73
+
74
+ def scrape_recommended_spec(page_contents)
75
+ spec_block = page_contents.xpath("//div[@data-os='win']/div[@class='game_area_sys_req_rightCol']/ul/ul")
76
+ scrape_spec(spec_block)
77
+ end
78
+
79
+ def scrape_spec(node)
80
+ spec_array = node.text.split "\r"
81
+ spec_hash = {}
82
+ spec_array.each do |entry|
83
+ value_pair = entry.split(':')
84
+ key = value_pair.first.to_sym
85
+ value = value_pair.last.strip
86
+ spec_hash[key] = value
87
+ end
88
+
89
+ spec_hash
90
+ end
91
+ end
@@ -0,0 +1,11 @@
1
+ # Retrieves a URL and return the Nokogiri representation of that page
2
+ require 'HTTParty'
3
+ require 'nokogiri'
4
+
5
+ # Class for retrieving a Nokogiri tree from a URL
6
+ class PageRetriever
7
+ def retrieve(url)
8
+ page_contents = HTTParty.get(url)
9
+ Nokogiri::HTML(page_contents)
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module SteamScraper
2
+ VERSION = '1.1.0'.freeze
3
+ end
@@ -0,0 +1,21 @@
1
+ require 'steam_scraper/version'
2
+ require 'steam_scraper/game_list_scraper'
3
+ require 'steam_scraper/game_page_scraper'
4
+
5
+ # Module that provides all SteamScraper functionality
6
+ module SteamScraper
7
+ # Class actually scrapes the Steam Store
8
+ class SteamScraper
9
+ def initialize(*_args)
10
+ @game_list_scraper = GameListScraper.new
11
+ @game_page_scraper = GamePageScraper.new
12
+ end
13
+
14
+ def scrape(first_page = 1, last_page = nil)
15
+ scraped_game_list = @game_list_scraper.scrape(first_page, last_page)
16
+ final_game_list = @game_page_scraper.scrape(scraped_game_list)
17
+
18
+ final_game_list
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'steam_scraper/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'steam_scraper'
8
+ spec.version = SteamScraper::VERSION
9
+ spec.authors = ['Robert Gardner']
10
+ spec.email = ['rantingbob@gmail.com']
11
+
12
+ spec.summary = 'Webscraper for the Steam Store'
13
+ spec.description = 'A webscraper that scrapes game data from store.steampowered.com'
14
+ spec.homepage = 'https://github.com/ShriekBob/steam_scraper'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.12'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'pry'
25
+ spec.add_development_dependency 'nokogiri', '~> 1.6.8'
26
+ spec.add_development_dependency 'httparty', '~> 0.14.0'
27
+ spec.add_runtime_dependency 'nokogiri', '~> 1.6.8'
28
+ spec.add_runtime_dependency 'httparty', '~> 0.14.0'
29
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: steam_scraper
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Robert Gardner
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.6.8
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.6.8
69
+ - !ruby/object:Gem::Dependency
70
+ name: httparty
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.14.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.14.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: nokogiri
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.6.8
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.6.8
97
+ - !ruby/object:Gem::Dependency
98
+ name: httparty
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.14.0
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.14.0
111
+ description: A webscraper that scrapes game data from store.steampowered.com
112
+ email:
113
+ - rantingbob@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rubocop.yml"
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - bin/console
125
+ - bin/setup
126
+ - lib/steam_scraper.rb
127
+ - lib/steam_scraper/game_list_scraper.rb
128
+ - lib/steam_scraper/game_page_scraper.rb
129
+ - lib/steam_scraper/page_retriever.rb
130
+ - lib/steam_scraper/version.rb
131
+ - steam_scraper.gemspec
132
+ homepage: https://github.com/ShriekBob/steam_scraper
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.5.1
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: Webscraper for the Steam Store
156
+ test_files: []