Php: how to obtain Baidu record, Baidu buzzword, and Baidu snapshot, and php Baidu Snapshot
This example describes how php can obtain Baidu's record, Baidu's buzzword, and Baidu's snapshot. Share it with you for your reference. The details are as follows:
Get Baidu record:
<? Php/* capture baidu indexed 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 ("locate related webpage (. *), ", $ site, $ count); $ count = str_replace (" find related webpage "," ", $ count); $ count = str_replace, "," ", $ count); $ count = str_replace (" approx "," ", $ count); $ count = str_replace (",","", $ count); return $ count [0];} echo baidu (www.jb51.net); // obtain the number of items included by the customer's home in baidu?>
Get Baidu's buzzwords
<? Php/*** @ return array return Baidu's popular word data (array return) */function getBaiduHotKeyWord () {$ templateRss = file_get_contents ('HTTP: // top.baidu.com/rss_xml.php? P = top10'); if (preg_match ('/<table> (. *) <\/table>/is ', $ templateRss, $ _ description) {$ templateRss =$ _ description [0]; $ templateRss = str_replace ("&", "&", $ templateRss) ;}$ templateRss = "<? Xml version = 1.0 encoding = GBK?> ". $ TemplateRss; $ xml = @ simplexml_load_String ($ templateRss); foreach ($ xml-> tbody-> tr as $ temp) {if (! Empty ($ temp-> td-> a) {$ keyArray [] = trim ($ temp-> td-> a) ;}} return $ keyArray ;} print_r (getBaiduHotKeyWord ());
This is a slight modification found on the Internet. Write the following code into the PHP file.
Baidu record and Baidu snapshot time
<? Php $ domain = "http://www.bkjia.com/* domain name to query */$ site_url = 'HTTP: // www.baidu.com/s? Wd = site % 3A '; $ all = $ site_url. $ domain;/* all URLs included in the domain name */$ today = $ all. '& lm = 1';/* Domain Name's URL indexed today */$ utf_pattern = "/find the number of results (. *)/"; $ kz_pattern ="/<span class = "g"> (. *) </span> /"; /* string used to match the snapshot date */$ times = "/d {4}-d {1, 2}-d {1, 2 }/"; /* match the regular expression of the snapshot date, for example, 2011-8-4 */$ s0 = @ file_get_contents ($ all);/* change site: put the webpage www.jb51.net into the $ s0 string */$ s1 = @ file_get_contents ($ today); preg_match ($ utf_pattern, $ s0, $ all_num ); /* match "find related results * "*/Preg_match ($ utf_pattern, $ s1, $ today_num); preg_match ($ kz_pattern, $ s0, $ 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";?> <Html>
I hope this article will help you with php programming.