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:
JavaScript
x
14
14
1
$('#rso').each(function (i, element) {
2
console('div level 1')
3
var title = $(this).find('.r').text();
4
var link = $(this).find('.r').find('a').attr('href').replace('/url?q=', '').split('&')[0];
5
var text = $(this).find('.st').text();
6
var img = $(this).find('img.th').attr('src');
7
savedData.push({
8
title: title,
9
link: link,
10
text: text,
11
img: img
12
});
13
});
14
Advertisement
Answer
You should use $$
instead
JavaScript
1
2
1
$$('#rso > div')
2
Reference
Console Utilities API Reference
$(selector) is alias to document.querySelector()
$$(selector) is alias to document.querySelectorAll()