views:

216

answers:

3

Hello,

I have a question.

How could I get the data from a google search response? I.e.:Results 1 - 100 of about 230,533,709 for blogs. (0.25 seconds)

I want to get the value 230,533,709.

I use php to get the html response from the url. I.e.: http://blogsearch.google.com/blogsearch?hl=en&ie=UTF-8&q=blogs&btnG=Search+Blogs

I use ajax to get the code from php:

$.ajax({
 url: "urlToPhp",
 type: "GET",
 dataType: "html",
 data: $('#form').serialize(),
 beforeSend: function(){}, 
 success: function(html) {
           ->what to do with html to get the value 230,533,709???
$('#results').html(test).show('slow');
}
});

Please help. I don't know how to do this. Regards!

+1  A: 

Have you tried using a selector (not tested, might need top adjust the selector):

var count = $(html).find('table.ttt td.rsb b:nth-child(2)').html();


UPDATE:

adjust the selector:

var count = $(html).find('b:eq(3)').html();
Darin Dimitrov
Thank, I tried it and get null.
Jooj
@Darin: `find('b:eq(3)')` works! Strangely though :)
o.k.w
A: 

How about this (basedon Darin's answer):

$('table.ttt td.rsb b:nth-child(3)').html();

I got 261,022,603

o.k.w
I tried var count = $(html).find('table.ttt td.rsb b:nth-child(3)').html();and still getting NULL! Don't know what's the problem?
Jooj
@o.k.w could you please paste the complete ajax code to see how you have got the result?
Jooj
@Jooj: Darin's answer of `find('b:eq(3)')` works, you should try that. This answer of mine tried without ajax fetching so not really ideal for you.
o.k.w
A: 

It still doesn't work. Could you please paste the complete code how you get the content and then parse the results value?

I tried this piece of code and doesn't work:

$("#results").load("http://blogsearch.google.com/blogsearch?hl=en&ie=UTF-8&q=blogs&btnG=Search+Blogs", function(data){
  alert(data); <- returns empty string
  alert($(data).text()); <-returns null
  alert($(data).find('b:eq(3)')); <- returns "[object Object]"
});

Why data is not the downloaded content. What means [object Object]?

Thank for your help.

Regards!

Jooj