采集百度百科城市介绍

隐藏行号 复制代码 这是一段程序代码。
  1. include_once  'Snoopy.class.php';
    
  2. 
    
  3. $word = '北京';
    
  4. $word = iconv('utf-8', 'gbk', $word);
    
  5. $url = "http://baike.baidu.com/search/word?word=".urlencode($word)."&pic=1&sug=1&enc=GBK";
    
  6. $url = iconv('utf-8', 'gbk', $url);
    
  7. 
    
  8. $snoopy = new Snoopy();
    
  9. 
    
  10. $arr = array();
    
  11. $snoopy->agent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11";
    
  12. $snoopy->setcookies('bk.doubt.tipbubble=1; undefined=show%3Dtrue; BAIDUID=3C8DBE160B442A473F00B534F2DC28EA:FG=1; bdshare_firstime=1362030797753; MAP_NEWDATA=V0; MAP_NEWDATA1=V1; BDREFER=%7Burl%3A%22http%3A//auto.baidu.com/%22%2Cword%3A%22%22%7D; BAIDULXBCB=19F69332B7BD0E7F6E5832BB5BC4B7F1AC3A33914F54038F85568856D663B7582917455BD3E27FBDB6923B0DA510DF1B201504AE9FBA9761ABE3C70DA6D3CC317663FBC33943D8527D7BD106461A334B; SSUDB=Ec4NWtsYlF5c045Q2hFTmxOVnNyanFJSlVhc1F2S29kSkVleFZpcUVFbnlOR1ZSQVFBQUFBJCQAAAAAAAAAAAEAAADF6f0MeXVoYW44MjM5Mjg4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPKnPVHypz1RO; PMS_Cache=1363068035843; BDUSS=Ec4NWtsYlF5c045Q2hFTmxOVnNyanFJSlVhc1F2S29kSkVleFZpcUVFbnlOR1ZSQVFBQUFBJCQAAAAAAAAAAAEAAADF6f0MeXVoYW44MjM5Mjg4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPKnPVHypz1RO; BDUT=4z5d3C8DBE160B442A473F00B534F2DC28EA13d1ecf54a30; MCITY=-2912%3A; IM_old=0|he9hpobl; H_PS_PSSID=1895_1444_1945_1788; Hm_lvt_55b574651fcae74b0a9f1cf9c8d7c93a=1363236133,1363236485,1363239512,1363239701; Hm_lpvt_55b574651fcae74b0a9f1cf9c8d7c93a=1363239701');
    
  13. 
    
  14. $snoopy->fetch($url);
    
  15. 
    
  16. echo $snoopy->results;