0

I am building a script to scrape data from a website. You can see the full code here: Undefined method 'click' for nil:NilClass (Mechanize)

Anyways, I have trouble to save this metadata into the database:

members = member_links.map do |link|

member = link.click
name = member.search('title').text.split('|')[0]
institution = member.search('td~ td+ td').text.split(':')[0]
dob = member.search('.birthdate').text.strip[1..4]

{
  name: name.strip,
  institution: institution.strip,
  dob: dob,
  bio: bio
}
end

Thus, how can I accomplish this?

Community
  • 1
  • 1
Ryzal Yusoff
  • 957
  • 2
  • 22
  • 49

1 Answers1

0

Well, it should be as simple as:

Datum.create!(
  name: name.strip,
  institution: institution.strip,
  dob: dob,
  bio: bio
)

This is very basic Rails knowledge, make sure you've read Active Record Basics guide.

Alexey Shein
  • 7,342
  • 1
  • 25
  • 38