seo-keywords-generator-ruby 0.1.9 → 0.1.11
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 +0 -3
- data/lib/seo-keywords-generator-ruby.rb +91 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c194e2d1710fd2d9ee64bb4a7fc1943812d430b780ae4d58d0decb161d9be782
|
4
|
+
data.tar.gz: 895cd9589b58d2cefff32c8896042119068cae7517f298e96e60640cec65a651
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ae40ae8282437ce336b7404cea767fdbfdbae78b2fbcdf0cf308a6a02fdad4fce469b9217525afadaf2678dc8334c6980f5b7973bbd7d140b451742d964a016
|
7
|
+
data.tar.gz: 77554adfde96256355bc02ebcbf05c499f43018d146fd2e16f2d16cce71d4cd2658bfc2b4f5a1f28c317cac00a54da1aa9fb54f3d8e69bc6ccf070a1b65b4dc8
|
data/bin/seo
CHANGED
@@ -3,9 +3,6 @@
|
|
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
6
|
require "seo-keywords-generator-ruby"
|
10
7
|
|
11
8
|
SeoKeywordsGenerator::CLI.new(ARGV).run
|
@@ -1,9 +1,99 @@
|
|
1
1
|
require 'google_search_results'
|
2
|
+
require 'optparse'
|
2
3
|
require 'json'
|
3
4
|
require 'csv'
|
4
5
|
|
5
6
|
module SeoKeywordsGenerator
|
6
|
-
|
7
|
+
class CLI
|
8
|
+
def initialize(argv)
|
9
|
+
@argv = argv
|
10
|
+
end
|
11
|
+
|
12
|
+
def run
|
13
|
+
options = {
|
14
|
+
engines: ['ac', 'rs', 'rq'],
|
15
|
+
depth_limit: 0,
|
16
|
+
save_to: 'CSV',
|
17
|
+
api_key: '5868ece26d41221f5e19ae8b3e355d22db23df1712da675d144760fc30d57988',
|
18
|
+
domain: 'google.com',
|
19
|
+
country: 'us',
|
20
|
+
lang: 'en',
|
21
|
+
}
|
22
|
+
|
23
|
+
OptionParser.new do |opts|
|
24
|
+
opts.banner = 'Usage: seo [options]'
|
25
|
+
|
26
|
+
opts.on('-q', '--query QUERY', String, 'Search query (required)') do |q|
|
27
|
+
options[:query] = q
|
28
|
+
end
|
29
|
+
|
30
|
+
opts.on('-e', '--engines ENGINES', Array, 'Choices of engines to extract: Autocomplete (ac), Related Searches (rs), People Also Ask (rq). You can select multiple engines by separating them with a comma: ac,rs. All engines are selected by default.') do |e|
|
31
|
+
options[:engines] = e
|
32
|
+
end
|
33
|
+
|
34
|
+
opts.on('-d', '--depth-limit LIMIT', Integer, 'Depth limit for People Also Ask. Default is 0, first 2-4 results.') do |dl|
|
35
|
+
options[:depth_limit] = dl
|
36
|
+
end
|
37
|
+
|
38
|
+
opts.on('-s', '--save-to SAVE', String, 'Saves the results in the current directory in the selected format (CSV, JSON, TXT). Default CSV.') do |st|
|
39
|
+
options[:save_to] = st
|
40
|
+
end
|
41
|
+
|
42
|
+
opts.on('-k', '--api-key KEY', String, 'Your SerpApi API key: https://serpapi.com/manage-api-key. Default is a test API key to test CLI.') do |ak|
|
43
|
+
options[:api_key] = ak
|
44
|
+
end
|
45
|
+
|
46
|
+
opts.on('-g', '--domain DOMAIN', String, 'Google domain: https://serpapi.com/google-domains. Default google.com.') do |gd|
|
47
|
+
options[:domain] = gd
|
48
|
+
end
|
49
|
+
|
50
|
+
opts.on('-c', '--country COUNTRY', String, 'Country of the search: https://serpapi.com/google-countries. Default us.') do |gl|
|
51
|
+
options[:country] = gl
|
52
|
+
end
|
53
|
+
|
54
|
+
opts.on('-l', '--language LANGUAGE', String, 'Language of the search: https://serpapi.com/google-languages. Default en.') do |hl|
|
55
|
+
options[:lang] = hl
|
56
|
+
end
|
57
|
+
end.parse!(@argv)
|
58
|
+
|
59
|
+
keyword_research = SeoKeywordsGenerator.new(
|
60
|
+
query=options[:query],
|
61
|
+
api_key=options[:api_key],
|
62
|
+
lang=options[:lang],
|
63
|
+
country=options[:country],
|
64
|
+
domain=options[:domain]
|
65
|
+
)
|
66
|
+
|
67
|
+
data = {}
|
68
|
+
|
69
|
+
options[:engines]&.each do |engine|
|
70
|
+
case engine.downcase
|
71
|
+
when 'ac'
|
72
|
+
data['auto_complete'] = keyword_research.get_auto_complete()
|
73
|
+
when 'rs'
|
74
|
+
data['related_searches'] = keyword_research.get_related_searches()
|
75
|
+
when 'rq'
|
76
|
+
data['related_questions'] = keyword_research.get_related_questions(options[:depth_limit])
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
if !data.empty?
|
81
|
+
keyword_research.print_data(data)
|
82
|
+
puts "Saving data in #{options[:save_to].upcase} format..."
|
83
|
+
|
84
|
+
case options[:save_to].upcase
|
85
|
+
when 'CSV'
|
86
|
+
keyword_research.save_to_csv(data)
|
87
|
+
when 'JSON'
|
88
|
+
keyword_research.save_to_json(data)
|
89
|
+
when 'TXT'
|
90
|
+
keyword_research.save_to_txt(data)
|
91
|
+
end
|
92
|
+
|
93
|
+
puts "Data successfully saved to #{options[:query].gsub(' ', '_')}.#{options[:save_to].downcase} file"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
7
97
|
|
8
98
|
class Scraper
|
9
99
|
attr_accessor :query, :api_key, :lang, :country, :domain
|