seo-keywords-generator-ruby 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/seo +8 -2
- data/lib/seo-keywords-generator-ruby.rb +108 -105
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3fcce4a4dae84b3eea8abefcf4dce39f10f9084c2b2f1ca90c5cb5e14ee06ab5
|
4
|
+
data.tar.gz: b0aa67a12d6d680e70f87793a4da42cd90f440209936aafb0e685dd049c2240b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93c5ac9430262fbb10f3a4654595718e980f3a3941011e58404285ca6e69809a53f866e85bcc49c67837df263b75f8fc2cc12ee8e36c97e1316f1a7ac54d1f83
|
7
|
+
data.tar.gz: 336d24b436d53d7c83a42fc5dd236ee6fe019286c5e324e70ce2769cdbf37b2bf2947f5b045e05ac942d413ed3ea011dbdccc260b201ad40299799fdacbab6ed
|
data/bin/seo
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
3
|
+
# frozen_string_literal: true
|
4
4
|
|
5
|
-
|
5
|
+
# Enable local usage from cloned repo
|
6
|
+
root = File.expand_path("../..", __FILE__)
|
7
|
+
$LOAD_PATH << "#{root}/lib" if File.exist?("#{root}/Gemfile")
|
8
|
+
|
9
|
+
require "seo-keywords-generator-ruby"
|
10
|
+
|
11
|
+
SeoKeywordsGenerator::CLI.new(ARGV).run
|
@@ -2,128 +2,131 @@ require 'google_search_results'
|
|
2
2
|
require 'json'
|
3
3
|
require 'csv'
|
4
4
|
|
5
|
+
module SeoKeywordsGenerator
|
6
|
+
autoload :CLI, "seo-keywords-generator-ruby/cli"
|
5
7
|
|
6
|
-
class
|
7
|
-
|
8
|
-
|
9
|
-
def initialize(query, api_key, lang = 'en', country = 'us', domain = 'google.com')
|
10
|
-
@query = query
|
11
|
-
@api_key = api_key
|
12
|
-
@lang = lang
|
13
|
-
@country = country
|
14
|
-
@domain = domain
|
15
|
-
@related_questions_results = []
|
16
|
-
end
|
17
|
-
|
18
|
-
def get_auto_complete
|
19
|
-
params = {
|
20
|
-
api_key: @api_key, # https://serpapi.com/manage-api-key
|
21
|
-
engine: 'google_autocomplete', # search engine
|
22
|
-
q: @query, # search query
|
23
|
-
gl: @country, # country of the search
|
24
|
-
hl: @lang # language of the search
|
25
|
-
}
|
26
|
-
|
27
|
-
search = GoogleSearch.new(params) # data extraction on the SerpApi backend
|
28
|
-
results = search.get_hash # JSON -> Ruby hash
|
8
|
+
class Scraper
|
9
|
+
attr_accessor :query, :api_key, :lang, :country, :domain
|
29
10
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
google_domain: @domain, # Google domain to use
|
39
|
-
gl: @country, # country of the search
|
40
|
-
hl: @lang # language of the search
|
41
|
-
}
|
11
|
+
def initialize(query, api_key, lang = 'en', country = 'us', domain = 'google.com')
|
12
|
+
@query = query
|
13
|
+
@api_key = api_key
|
14
|
+
@lang = lang
|
15
|
+
@country = country
|
16
|
+
@domain = domain
|
17
|
+
@related_questions_results = []
|
18
|
+
end
|
42
19
|
|
43
|
-
|
44
|
-
|
20
|
+
def get_auto_complete
|
21
|
+
params = {
|
22
|
+
api_key: @api_key, # https://serpapi.com/manage-api-key
|
23
|
+
engine: 'google_autocomplete', # search engine
|
24
|
+
q: @query, # search query
|
25
|
+
gl: @country, # country of the search
|
26
|
+
hl: @lang # language of the search
|
27
|
+
}
|
28
|
+
|
29
|
+
search = GoogleSearch.new(params) # data extraction on the SerpApi backend
|
30
|
+
results = search.get_hash # JSON -> Ruby hash
|
31
|
+
|
32
|
+
results[:suggestions].map{ |result| result[:value] }.compact
|
33
|
+
end
|
45
34
|
|
46
|
-
|
47
|
-
|
35
|
+
def get_related_searches
|
36
|
+
params = {
|
37
|
+
api_key: @api_key, # https://serpapi.com/manage-api-key
|
38
|
+
engine: 'google', # search engine
|
39
|
+
q: @query, # search query
|
40
|
+
google_domain: @domain, # Google domain to use
|
41
|
+
gl: @country, # country of the search
|
42
|
+
hl: @lang # language of the search
|
43
|
+
}
|
44
|
+
|
45
|
+
search = GoogleSearch.new(params) # data extraction on the SerpApi backend
|
46
|
+
results = search.get_hash # JSON -> Ruby hash
|
47
|
+
|
48
|
+
results[:related_searches].map{ |result| result[:query] }.compact
|
49
|
+
end
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
51
|
+
def get_depth_results(token, depth)
|
52
|
+
depth_params = {
|
53
|
+
q: @query,
|
54
|
+
api_key: @api_key,
|
55
|
+
engine: 'google_related_questions',
|
56
|
+
next_page_token: token
|
57
|
+
}
|
58
|
+
|
59
|
+
depth_search = GoogleSearch.new(depth_params)
|
60
|
+
depth_results = depth_search.get_hash
|
61
|
+
|
62
|
+
@related_questions_results += depth_results[:related_questions]&.map{ |result| result[:question] }
|
63
|
+
|
64
|
+
if depth > 1
|
65
|
+
depth_results[:related_questions]&.each do |question|
|
66
|
+
if question[:next_page_token]
|
67
|
+
get_depth_results(question[:next_page_token], depth - 1)
|
68
|
+
end
|
66
69
|
end
|
67
70
|
end
|
68
71
|
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def get_related_questions(depth_limit = 0)
|
72
|
-
params = {
|
73
|
-
api_key: @api_key, # https://serpapi.com/manage-api-key
|
74
|
-
engine: 'google', # search engine
|
75
|
-
q: @query, # search query
|
76
|
-
google_domain: @domain, # Google domain to use
|
77
|
-
gl: @country, # country of the search
|
78
|
-
hl: @lang # language of the search
|
79
|
-
}
|
80
|
-
|
81
|
-
search = GoogleSearch.new(params) # data extraction on the SerpApi backend
|
82
|
-
results = search.get_hash # JSON -> Ruby hash
|
83
72
|
|
84
|
-
|
73
|
+
def get_related_questions(depth_limit = 0)
|
74
|
+
params = {
|
75
|
+
api_key: @api_key, # https://serpapi.com/manage-api-key
|
76
|
+
engine: 'google', # search engine
|
77
|
+
q: @query, # search query
|
78
|
+
google_domain: @domain, # Google domain to use
|
79
|
+
gl: @country, # country of the search
|
80
|
+
hl: @lang # language of the search
|
81
|
+
}
|
82
|
+
|
83
|
+
search = GoogleSearch.new(params) # data extraction on the SerpApi backend
|
84
|
+
results = search.get_hash # JSON -> Ruby hash
|
85
|
+
|
86
|
+
@related_questions_results = results[:related_questions]&.map{ |result| result[:question] }
|
87
|
+
|
88
|
+
depth_limit = 4 if depth_limit > 4
|
89
|
+
|
90
|
+
if depth_limit > 0
|
91
|
+
results[:related_questions]&.each do |question|
|
92
|
+
if question[:next_page_token]
|
93
|
+
get_depth_results(question[:next_page_token], depth_limit)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
85
97
|
|
86
|
-
|
98
|
+
@related_questions_results
|
99
|
+
end
|
87
100
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
101
|
+
def save_to_csv(data)
|
102
|
+
CSV.open("#{@query.gsub(' ', '_')}.csv", 'w') do |csv_file|
|
103
|
+
csv_file << data.keys
|
104
|
+
max_length = data.values.map(&:length).max
|
105
|
+
(0...max_length).each do |index|
|
106
|
+
csv_file << data.values.map { |value| value[index] }
|
92
107
|
end
|
93
108
|
end
|
94
109
|
end
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
def save_to_csv(data)
|
100
|
-
CSV.open("#{@query.gsub(' ', '_')}.csv", 'w') do |csv_file|
|
101
|
-
csv_file << data.keys
|
102
|
-
max_length = data.values.map(&:length).max
|
103
|
-
(0...max_length).each do |index|
|
104
|
-
csv_file << data.values.map { |value| value[index] }
|
110
|
+
|
111
|
+
def save_to_json(data)
|
112
|
+
File.open("#{@query.gsub(' ', '_')}.json", 'w') do |json_file|
|
113
|
+
json_file.write(JSON.pretty_generate(data))
|
105
114
|
end
|
106
115
|
end
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
def save_to_txt(data)
|
116
|
-
File.open("#{@query.gsub(' ', '_')}.txt", "w") do |txt_file|
|
117
|
-
data.each do |key, values|
|
118
|
-
txt_file.puts("#{key}:")
|
119
|
-
values.each do |value|
|
120
|
-
txt_file.puts(" #{value}")
|
116
|
+
|
117
|
+
def save_to_txt(data)
|
118
|
+
File.open("#{@query.gsub(' ', '_')}.txt", "w") do |txt_file|
|
119
|
+
data.each do |key, values|
|
120
|
+
txt_file.puts("#{key}:")
|
121
|
+
values.each do |value|
|
122
|
+
txt_file.puts(" #{value}")
|
123
|
+
end
|
121
124
|
end
|
122
125
|
end
|
123
126
|
end
|
127
|
+
|
128
|
+
def print_data(data)
|
129
|
+
puts JSON.pretty_generate(data)
|
130
|
+
end
|
124
131
|
end
|
125
|
-
|
126
|
-
def print_data(data)
|
127
|
-
puts JSON.pretty_generate(data)
|
128
|
-
end
|
129
|
-
end
|
132
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seo-keywords-generator-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artur Chukhrai
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-
|
12
|
+
date: 2023-07-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: google_search_results
|