0

我正在开发一个应用程序,我需要在其中获取和保存网站的打开图形数据。

到目前为止,我已经能够使用此代码获取标题、描述、url 等属性

before_save :get_meta_from_link

def check_link
        begin
            @page_link = MetaInspector.new(sanitized_url)
        rescue Faraday::ConnectionFailed => e
            errors.add(:link, "Oops, can't be processed ATM")
        end
    end

  def get_meta_from_link
        page = @page_link
        return unless page.to_hash.present?

    if page.title.present?
      self.title = page.title
        end

    if page.description.present?
      self.description = page.description
    end

    if page.url.present?
      self.url = page.url
    end

    end

我正在使用 metaspector gem 并尝试获取诸如 og:locale、og:type 之类的值。我怎样才能获取这些值?

这是我用来交叉引用值的链接:https ://metainspectordemo.herokuapp.com

4

1 回答 1

0

好的,所以我设法使用

def check_link
        begin
            @page_link = MetaInspector.new(sanitized_url)
        rescue MetaInspector::RequestError => e
            errors.add(:link, "you provided is not being read by our system. Please check the link.")
        end
    end

在我的链接模型中

其次是

def get_meta_from_link
        page = @page_link
    paje = @page_link.meta_tags
        return unless page.to_hash.present?

    if page.title.present?
      self.btitle = page.title
        end
end
于 2017-10-22T09:55:08.720 回答