Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9104863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:57:44+00:00 2026-06-17T01:57:44+00:00

I am trying to parse og meta tags using the HTTParty gem using this

  • 0

I am trying to parse og meta tags using the HTTParty gem using this code:

link = http://www.usatoday.com/story/gameon/2013/01/08/nfl-jets-tony-sparano-fired/1817037/
# link = http://news.yahoo.com/chicago-lottery-winners-death-ruled-homicide-181627271.html
resp = HTTParty.get(link)
ret_body = resp.body

# title
  og_title = ret_body.match(/\<[Mm][Ee][Tt][Aa] property\=\"og:title\"\ content\=\"(.*?)\"\/\>/)
  og_title = og_title[1].to_s

The problem is that it worked on some sites (yahoo!) but not others (usa today)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T01:57:46+00:00Added an answer on June 17, 2026 at 1:57 am

    Don’t parse HTML with regular expressions, because they’re too fragile for anything but the simplest problems. A tiny change to the HTML can break the pattern, causing you to begin a slow battle of maintaining an ever expanding pattern. It’s a war you won’t win.

    Instead, use a HTML parser. Ruby has Nokogiri, which is excellent. Here’s how I’d do what you want:

    require 'nokogiri'
    require 'httparty'
    
    %w[
      http://www.usatoday.com/story/gameon/2013/01/08/nfl-jets-tony-sparano-fired/1817037/
      http://news.yahoo.com/chicago-lottery-winners-death-ruled-homicide-181627271.html
    ].each do |link|
      resp = HTTParty.get(link)
    
      doc = Nokogiri::HTML(resp.body)
      puts doc.at('meta[property="og:title"]')['content']
    end
    

    Which outputs:

    Jets fire offensive coordinator Tony Sparano
    Chicago lottery winner's death ruled a homicide
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to parse meta tags with Scala. I've tried just doing this with
Im trying to parse a website using the Mechanize Gem. So far this is
Trying to parse some XML but apparently this is too much for a lazy
Im trying to parse the string located in /proc/stat in a linux filesystem using
I have an xml feed at this url Now im trying parse the content,
Trying to parse this and return the following 3 items: -30.25 31.46 -27.46 31.74
I'm trying to parse the result of a HEAD request done using the Python
I've been trying to parse the phpunit json log using jquery however it returns
I'm trying to parse some html using jsoup (1.3.3) in my android activity. When
I'm using wordpress and one of my meta key values is stored like this:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.