用php爬取网页

用到了强大的curl库。

代码:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset:UTF-8">
<title>sh</title>
</head>
<body>
<form action="search.php">
<input type="text" name="find" size="50"/>
  <input type="submit" name="submit"  value="search"/>
</form>
</body>
</html>

 

<?php
if(isset($_GET['find']))
{
   $cv=$_GET['find'];
   $nw=urlencode($cv);
   $ch=curl_init();
   curl_setopt($ch,CURLOPT_URL,"http://www.baidu.com/s?wd=".$cv."&pn=0");
   curl_setopt($ch,CURLOPT_HEADER,0);
   curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
   $output=curl_exec($ch);
   curl_close($ch);
   echo $output;
}
?>

 

posted @ 2013-05-28 09:24  xshang  阅读(2634)  评论(0编辑  收藏  举报