Skip to content

Commit

Permalink
Update scraper.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
BfB-Schenefeld committed Apr 21, 2024
1 parent 99c804c commit e1aee8f
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions scraper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,25 @@ def scrape_calendar_data(year, month)
url = "https://www.sitzungsdienst-schenefeld.de/bi/si010_r.asp?MM=#{month}&YY=#{year}"
puts "Attempting to access URL: #{url}"
begin
document = Nokogiri::HTML(URI.open(url))
document = Nokogiri::HTML(open(url)) # Use open directly as per Ruby 2.0.0
puts "Page loaded successfully."
links_found = document.css('a[href*="si010_r.asp?DD="]')
puts "Number of matching links found: #{links_found.count}"
links_found.each do |link|
day = link['href'][/DD=(\d+)/, 1]
month = link['href'][/MM=(\d+)/, 1]
year = link['href'][/YY=(\d+)/, 1]
formatted_date = "#{day}.#{month}.#{year}"
puts "Datum: #{formatted_date}, URL: #{link['href']}"

if links_found.empty?
puts "No links matching the criteria were found."
else
links_found.each do |link|
day = link['href'][/DD=(\d+)/, 1]
month = link['href'][/MM=(\d+)/, 1]
year = link['href'][/YY=(\d+)/, 1]
formatted_date = "#{day}.#{month}.#{year}"
puts "Datum: #{formatted_date}, URL: #{link['href']}"
end
end
rescue StandardError => e
puts "Error during calendar data scrape: #{e.message}"
end
end

scrape_calendar_data(2024, 3)

0 comments on commit e1aee8f

Please sign in to comment.