2009-10-31 107 views
0

我有一個問題。使用jquery獲得谷歌「關於結果1-100」? 「for ...」的值

如何從Google搜索響應中獲取數據? 即:針對博客的結果1 - 100約爲230,533,709。 (0.25秒)

我想要得到值230,533,709

我使用php從url獲取html響應。 即:http://blogsearch.google.com/blogsearch?hl=en&ie=UTF-8&q=blogs&btnG=Search+Blogs

我用ajax從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'); 
} 
}); 

請幫助。我不知道該怎麼做。 關心!


它仍然不起作用。你能否粘貼完整的代碼,如何獲取內容,然後解析結果值?

我想這段代碼並不起作用:

$("#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]" 
}); 

爲什麼數據不是下載的內容。什麼意思[對象對象]?

感謝您的幫助。

問候!

回答

1

您是否嘗試過使用選擇(沒有測試,可能需要頂部調整選擇):

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

UPDATE:

調整選擇:

var count = $(html).find('b:eq(3)').html(); 
+0

謝謝,我試了一下,並得到空。 – Jooj 2009-10-31 10:34:04

+0

@Darin:'find('b:eq(3)')'的作品!奇怪雖然:) – 2009-10-31 11:08:22

0

如何關於這個(基於達林的回答):

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

261,022,603

+0

我試過 var count = $(html).find('table.ttt td.rsb b:nth-​​child(3)')。html(); 仍然是NULL! 不知道是什麼問題? – Jooj 2009-10-31 10:50:35

+0

@ o.k。你能不能粘貼完整的ajax代碼來看看你是如何得到結果的? – Jooj 2009-10-31 15:33:39

+0

@Jooj:Darin對find('b:eq(3)')的回答是有效的,你應該試試。我的這個答案沒有ajax提取嘗試,所以對你來說不是很理想。 – 2009-11-01 04:08:55

0

好主意是 -

  1. ,要考慮與所有的preg_match HTML
  2. 解析在PHP $。員額()()
  3. 得到結果

對谷歌網頁不使用jquery。