PHP crawl Baidu Snapshot, Baidu included, Baidu hot Word program code

Source: Internet
Author: User
Tags echo date

<?
/*
Crawl Baidu included code
*/
function Baidu ($s) {
$baidu = "Http://www.baidu.com/s?wd=site%3A". $s;
$site =file_get_contents ($baidu);
$site =iconv ("gb2312", "UTF-8", $site);
Ereg ("Find related pages (. *),", $site, $count);
$count =str_replace ("Find related pages", "", $count);
$count =str_replace ("article,", "", $count);
$count =str_replace ("About", "", $count);
$count =str_replace (",", "", $count);
return $count [0];
}

echo Baidu (www.hzhuti.com); Get the number of good topics included in Baidu

?>



Get Baidu's hot words






















Print_r (Getbaiduhotkeyword ());



This is on the Internet to find a slightly modified under the following code to write to the PHP file
Baidu included and Baidu snapshot time

<?php
$domain = "http://www.hzhuti.com/nokia/5230/* Domain name to query * *
$site _url = ' Http://www.baidu.com/s?wd=site%3A ';
$all = $site _url. $domain; /* All included URLs for domain */
$today = $all. ' &lm=1′; /* Domain name included in today's URL */
$utf _pattern = "/Find the relevant result number (. *)/";
$kz _pattern = "/<span class=" G "> (. *) </span>/"; /* String to match the snapshot date */
$times = "/d{4}-d{1,2}-d{1,2}/"; /* Regular expressions that match the snapshot date, such as: 2011-8-4*/
$s 0 = @file_get_contents ($all); /* Place the Site:www.ninthday.net Web page into the $s0 string */
$s 1 = @file_get_contents ($today);
Preg_match ($utf _pattern, $s 0, $all _num); /* Match "find related results * *" * *
Preg_match ($utf _pattern, $s 1, $today _num);
Preg_match ($kz _pattern, $s 0, $temp);
Preg_match ($times, $temp [0], $screenshot);
if ($all _num[1] = = "")
$all _num[1] = 0;
if ($today _num[1] = = "")
$today _num[1] = 0;
if ($screenshot [0] = = "")
$screenshot [0] = "no snapshot";
?>
<title>Test</title>
<body>
<table>
<tr>
<td> date </td><td> Baidu included </td><td> Baidu today included </td><td> Baidu Snapshot Date </td>
</tr>
<tr>
<td><?php echo Date (' m ' D Day G ');? > </td><td><?php echo $all _num[1];? ></td><td><?php Echo $today _num[1];?>< /td><td><?php echo $screenshot [0];?></td>
</tr>

</table>
<p> Baidu included: <a href= "<?php echo $all;?>" target= "_blank" ><?php echo $all _num[1];?></a>< /p>
<p> Baidu today included: <a href= "<?php echo $today;?>" target= "_blank" ><?php echo $today _num[1];? ></a ></p>
<p> Baidu Snapshot Date: <a href= "<?php echo $all;?>" ><?php echo $screenshot [0];?></a></p>
</body>



The above method is not strictly considered, if the server does not support the File_get_contents function we can not operate, so also use curl operation, this is more convenient to imitate the user Oh.

PHP crawl Baidu Snapshot, Baidu included, Baidu hot Word program code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.