Class: Apollo::Fetcher::BaseFetcher
- Inherits:
-
Object
- Object
- Apollo::Fetcher::BaseFetcher
show all
- Defined in:
- lib/apollo_crawler/fetcher/base_fetcher.rb
Class Method Summary
collapse
Class Method Details
.fetch(url, options = {}) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/apollo_crawler/fetcher/base_fetcher.rb', line 41
def self.fetch(url, options = {})
begin
uri = URI.parse(url.to_s)
rescue Exception => e
puts "EXCEPTION: BaseFetcher::fetch() - Unable to fetch: '#{e.to_s}'"
return nil
end
conn = Faraday.new(:url => url) do |faraday|
faraday.adapter Faraday.default_adapter end
begin
res = conn.get(uri) do |request|
request. = BaseFetcher.(uri)
end
rescue Exception => e
puts "EXCEPTION: BaseFetcher::fetch() - Unable to fetch: '#{e.to_s}'"
return nil
end
return res
end
|
33
34
35
36
37
38
39
|
# File 'lib/apollo_crawler/fetcher/base_fetcher.rb', line 33
def self.(url)
ip = IPAddr.new(rand(2**32), Socket::AF_INET).to_s
return {
"X-Forwarded-For" => ip
}
end
|