-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorthochristian.rb
More file actions
60 lines (41 loc) · 1.24 KB
/
orthochristian.rb
File metadata and controls
60 lines (41 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# frozen_string_literal: true
require 'httparty'
require 'nokogiri'
require 'logger'
require_relative 'lib/element'
=begin
# set up logger and data store
log_file = File.open('database.log', File::WRONLY | File::APPEND)
data_log = Logger.new(log_file)
connection = PG.connect(hostaddr: '23.239.16.24', port: 5432, dbname: 'scrapedata', user: 'linpostgres',
password: '')
=end
DEBUG = 1
# load the page
doc = Nokogiri::HTML(HTTParty.get('https://orthochristian.com/202/').body)
# find all links
links = doc.search('a')
# see how many we're working with
puts "There are #{links.size} links found"
# title of the document
puts doc.title
class Article < LinkElement
end
html = doc.search('.list-articles-wide__uppertitle a')
# puts html
recent_articles = []
html.each do |article_content|
a = Article.new(article_content['href'], article_content.text.strip)
recent_articles << a
end
recent_articles = recent_articles.uniq.sort
# display contents
File.open('orthochristian.txt', 'w') do |file|
recent_articles.each do |article|
file << article.to_s
end
end
# get final count
puts "#{recent_articles.size} Program elements scraped"
# display for debugging purposes
pp recent_articles if DEBUG == 1