medialab / artoo

artoo.js - the client-side scraping companion.
http://medialab.github.io/artoo/
MIT License
1.1k stars 93 forks source link

Go up in the DOM #238

Open crmn111 opened 8 years ago

crmn111 commented 8 years ago

Is it possible to go up in the DOM from whithin a function? I am trying something like this $(this).parents():

When i log out the index of $(this) it is always 0.

artoo.scrape('.g.g--f', { title: {sel: 'a.bdrn.tct'}, category: function($) { //console.log(+$(this).index()); return $(this).parents('.card-section').find('.h3.mbm').html(); }, parts: function ($) { return artoo.scrape($(this).find('.bucket.bucket--flag'), { title: {sel: 'h4'} }); } });

Yomguithereal commented 8 years ago

Hello @dirkjan111. You can go up in the DOM with jQuery's methods as you do here.

$(this) should be the element matched by .g.g--f in the iteration.

Can you find me the dom you are trying to scrape, or even the webpage so I can help you better?