Ruby: Unable to capture Baidu search results

  question, ruby

URL:http://www.baidu.com/s? wd=site:www.cnblogs.com
Code:

def get_html(url)
 uri = URI(url)
 p resp = Net::HTTP.get(uri)
 end

The result obtained is the source code of Baidu’s homepage, not a search.site:www.cnblogs.comResults of


I don’t know, are there any good books on network programming in Ruby?
I have just come into contact with ruby, and I don’t know where to find many things (at present, I go to the official website to see the documents).


The following is simply implemented using PHP:

<?  php
 set_time_limit(0);
 function _rand()
 {
 $length = 26;
 $chars = "0123456789abcdefghijklmnopqrstuvwxyz";
 $max = strlen($chars) - 1;
 mt_srand((double)microtime() * 1000000);
 $string = '';
 for ($i = 0;   $i < $length;  $i++) {
 $string.= $chars[mt_rand(0, $max) ];
 }
 return $string;
 }
 $HTTP_SESSION = _rand();
 $HTTP_SESSION;
 $HTTP_Server = "www.baidu.com";
 $HTTP_URL = "/s?  wd=site:www.cnblogs.com";
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, "http://" . $HTTP_Server . $HTTP_URL);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;   MSIE 6.0;   Windows NT 5.1;   SV1;   .NET CLR 1.1.4322;   .NET CLR 2.0.50727)");
 $res = curl_exec($ch);
 curl_close($ch);
 print_r($res);

No matter what language code you use to capture, you cannot capture Baidu’s content so easily.
Baidu is not the same Baidu as before. Without all kinds of cookie authentication, you can’t catch a fart. You’d better study and see if there is any api. The code at the front of Baidu is all around, so that you won’t catch it.