newegg_scraper_chsbr 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6f2133128bd60c1e34d9d7ed98d65aa0bd5c305c804a4491738c22ea6b48931
|
4
|
+
data.tar.gz: f431eac85ce8616a3143537293e3b552a50056bb83b7afd84d6f0be525387b90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32761b7f137118cd0b9ff915b745078f28ed74402ded5cfee1163196a6412e5904e53a5c8be73a8c818e637fa98884f483c714c3c62297a4c9b0dbded09d5fbd
|
7
|
+
data.tar.gz: deefa949cc5df1ea06cd1bf75a6977277b76573ac2ad9c1b5a2fc6fb01dc921bb7ed4163c9a1f1df5518f19cbaeddbc5df6b6afc7a7e58f643205bc42ef5f7f9
|
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
class NeweggScraperChsbr::DataGrabber
|
3
2
|
attr_reader :cpus
|
4
3
|
|
@@ -9,7 +8,7 @@ class NeweggScraperChsbr::DataGrabber
|
|
9
8
|
names = getNames
|
10
9
|
descHash = getCpuDesc
|
11
10
|
@cpus = makeCpus(prices, names, shipping_price, descHash)
|
12
|
-
end
|
11
|
+
end
|
13
12
|
|
14
13
|
def getCpuDesc
|
15
14
|
scraped = NeweggScraperChsbr::Scraper.new
|
@@ -18,7 +17,10 @@ class NeweggScraperChsbr::DataGrabber
|
|
18
17
|
css_next_link = scraped.xml_obj.css ".item-title"
|
19
18
|
css_next_link.each_with_index do | element, index |
|
20
19
|
if index != 0
|
21
|
-
|
20
|
+
|
21
|
+
if element.attributes["href"] != nil
|
22
|
+
pages << element.attributes["href"].text
|
23
|
+
end
|
22
24
|
end
|
23
25
|
end
|
24
26
|
description = {}
|
@@ -44,19 +46,19 @@ class NeweggScraperChsbr::DataGrabber
|
|
44
46
|
|
45
47
|
|
46
48
|
end
|
47
|
-
def split_price(html_element)
|
49
|
+
def split_price(html_element)
|
48
50
|
counter = 0
|
49
51
|
until counter == 100
|
50
|
-
if counter < 10
|
51
|
-
if html_element.text.include?(".0#{counter.to_s}")
|
52
|
-
|
53
|
-
price = html_element.text.split ".0#{counter.to_s}"
|
54
|
-
|
55
|
-
|
52
|
+
if counter < 10
|
53
|
+
if html_element.text.include?(".0#{counter.to_s}")
|
54
|
+
|
55
|
+
price = html_element.text.split ".0#{counter.to_s}"
|
56
|
+
|
57
|
+
|
56
58
|
price.delete_at 1
|
57
|
-
return price, ".0#{counter.to_s}"
|
59
|
+
return price, ".0#{counter.to_s}"
|
58
60
|
end
|
59
|
-
elsif counter >= 10
|
61
|
+
elsif counter >= 10
|
60
62
|
if html_element.text.include?(".#{counter.to_s}")
|
61
63
|
|
62
64
|
price = (html_element.text.split ".#{counter.to_s}")
|
@@ -67,59 +69,35 @@ class NeweggScraperChsbr::DataGrabber
|
|
67
69
|
counter += 1
|
68
70
|
end
|
69
71
|
end
|
70
|
-
def isCoolerOrMB?(name)
|
71
|
-
name.include?("Water") || name.include?("Air") || name.include?("Motherboard")
|
72
|
-
# any of the products include
|
73
|
-
# words that describe motherboards and/or
|
74
|
-
# cooling products.
|
72
|
+
def isCoolerOrMB?(name)
|
73
|
+
name.include?("Water") || name.include?("Air") || name.include?("Motherboard")
|
75
74
|
end
|
76
75
|
def getPrice
|
77
76
|
scraped_info = NeweggScraperChsbr::Scraper.new
|
78
|
-
css_price = scraped_info.xml_obj.css ".price-current"
|
79
|
-
# html that contains what I need to find the price.
|
77
|
+
css_price = scraped_info.xml_obj.css ".price-current"
|
80
78
|
|
81
|
-
prices = []
|
82
|
-
|
83
|
-
css_price.each do | piece | # Going 1 level deep into the html obj that contains the price text element.
|
84
|
-
|
85
|
-
temp_price = split_price piece # split_price will split the price, and return
|
86
|
-
# two variables in an array. The first element of
|
87
|
-
# the array will be the dollar amount.
|
88
|
-
# The second element will be the cent ammount because
|
89
|
-
# I deemed it easier to remove anything after the
|
90
|
-
# floating point, it was the only pattern that was
|
91
|
-
# consistent.
|
79
|
+
prices = []
|
92
80
|
|
81
|
+
css_price.each do | piece |
|
82
|
+
temp_price = split_price piece
|
93
83
|
if temp_price != nil
|
94
|
-
temp_price.flatten!
|
95
|
-
|
96
|
-
# to return the flattened array to temp_price.
|
97
|
-
|
98
|
-
prices << "#{temp_price[0]}#{temp_price[1]}" # Here prices is being shoveled the
|
99
|
-
# two elements, concatenated to create
|
100
|
-
# a string similar to "$00.00"
|
84
|
+
temp_price.flatten!
|
85
|
+
prices << "#{temp_price[0]}#{temp_price[1]}"
|
101
86
|
end
|
102
87
|
|
103
|
-
end
|
88
|
+
end
|
104
89
|
prices
|
105
90
|
end
|
106
91
|
def getNames
|
107
92
|
scraped = NeweggScraperChsbr::Scraper.new
|
108
|
-
names = []
|
109
|
-
# objects found on the page.
|
93
|
+
names = []
|
110
94
|
|
111
|
-
css_name = scraped.xml_obj.css ".item-title"
|
112
|
-
# object to be enumerated upon.
|
95
|
+
css_name = scraped.xml_obj.css ".item-title"
|
113
96
|
|
114
|
-
css_name.each_with_index do | name, index |
|
115
|
-
# to retrieve the strings.
|
97
|
+
css_name.each_with_index do | name, index |
|
116
98
|
|
117
|
-
index != 0 ? names << name.text : nil
|
118
|
-
|
119
|
-
# After I skip the first name
|
120
|
-
# I will shovel the text from the
|
121
|
-
# html object into the names array.
|
122
|
-
end #end names.each_with_index
|
99
|
+
index != 0 ? names << name.text : nil
|
100
|
+
end
|
123
101
|
names
|
124
102
|
end
|
125
103
|
def getShipping
|
@@ -136,23 +114,13 @@ class NeweggScraperChsbr::DataGrabber
|
|
136
114
|
|
137
115
|
|
138
116
|
cpus = []
|
139
|
-
prices.each_with_index do | price, index |
|
140
|
-
# each of the prices with their
|
141
|
-
# index so that the enumation can
|
142
|
-
# access the names array at the
|
143
|
-
# same time.
|
117
|
+
prices.each_with_index do | price, index |
|
144
118
|
|
145
|
-
if !isCoolerOrMB?(names[index])
|
146
|
-
# the name is a cooler
|
147
|
-
# or motherboard because
|
148
|
-
# there is a price associated
|
149
|
-
# with the coolers on the
|
150
|
-
# website.
|
151
|
-
|
119
|
+
if !isCoolerOrMB?(names[index])
|
152
120
|
cpus << NeweggScraperChsbr::Cpu.new(names[index], price, shipping[index], desc_hash[index])
|
153
121
|
|
154
|
-
end
|
155
|
-
end
|
122
|
+
end
|
123
|
+
end
|
156
124
|
cpus
|
157
125
|
end
|
158
126
|
end
|
@@ -4,7 +4,7 @@ class NeweggScraperChsbr::Scraper
|
|
4
4
|
|
5
5
|
URL = "https://www.newegg.com/p/pl?d=cpu"
|
6
6
|
def initialize(url = URL)
|
7
|
-
@xml_obj = Nokogiri::HTML(URI.open(url))
|
7
|
+
@xml_obj = Nokogiri::HTML(URI.open(url))
|
8
8
|
end
|
9
9
|
|
10
10
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: newegg_scraper_chsbr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lrd134
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-04-
|
11
|
+
date: 2021-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|