From Google news I’m attempting to parse the results. For example, parse the title and text from the search “latest movie releases”, here is the URL:
The results appear to use #rso in the id:
But the iterator over $('#rso').each
is empty. What id or css element should I select in order to iterate over the divs of search results ?
Iterator code:
$('#rso').each(function (i, element) { console('div level 1') var title = $(this).find('.r').text(); var link = $(this).find('.r').find('a').attr('href').replace('/url?q=', '').split('&')[0]; var text = $(this).find('.st').text(); var img = $(this).find('img.th').attr('src'); savedData.push({ title: title, link: link, text: text, img: img }); });
Advertisement
Answer
You should use $$
instead
$$('#rso > div')
Reference
Console Utilities API Reference
$(selector) is alias to document.querySelector()
$$(selector) is alias to document.querySelectorAll()