Ruby: Unable to capture Baidu search results

  question, ruby


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

The result obtained is the source code of Baidu’s homepage, not a 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
 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_Server = "";
 $HTTP_URL = "/s?";
 $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);

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.