venturz909
venturz909

Reputation: 330

jQuery Selector & Cheerio

I'm trying to make a selector to scrape a pinterest image. The selector I made grabs the first version of the selector which is an avatar wrapped in its own div. I want to grab the 2nd instance of the selector which is the actual image

This is my selector: ("meta[itemprop = 'image']").attr('content');

This what I want to get <meta itemprop="image" content="https://s-media-cache-ak0.pinimg.com/originals/11/9d/fa/119dfa7dbf8ba60e694f994e38c0622b.jpg">

Here is the pinterest page link I'm attempting to scrape: https://www.pinterest.com/pin/374784000210632724/

Upvotes: 1

Views: 631

Answers (2)

Ajouve
Ajouve

Reputation: 10089

You can do it faster with eq(i). If you want the second element:

$("meta[itemprop = 'image']").eq(1).attr('content');

Link to the doc

Upvotes: 1

MarkSkayff
MarkSkayff

Reputation: 1374

Looks you want to grab the second occurence of $("meta[itemprop = 'image']")

In that case you must grab that specific instance, for example like this:

var domElem = $("meta[itemprop = 'image']").get(1);

And then you grab the attribute content like you wrote above:

var content = $(domElem).attr('content');

Upvotes: 2

Related Questions