首页  >  文章  >  后端开发  >  PHP抓取网页代码示例

PHP抓取网页代码示例

WBOY
WBOY原创
2016-07-25 08:46:10987浏览
  1. //PHP(前提是装了curl):
  2. $ch = curl_init();
  3. curl_setopt ($ch, CURLOPT_URL, "http://www.xxx/");
  4. curl_setopt ($ch, CURLOPT_REFERER, "http://www.xxx/");
  5. curl_exec ($ch);
  6. curl_close ($ch);
  7. //PHP(不装curl用sock)
  8. $server = 'blog.qita.in';
  9. $host = 'blog.qita.in';
  10. $target = '/xxx.asp';
  11. $referer = 'http://blog.qita.in/'; // Referer
  12. $port = 80;
  13. $fp = fsockopen($server, $port, $errno, $errstr, 30);
  14. if (!$fp)
  15. {
  16. echo "$errstr ($errno)
    \n";
  17. }
  18. else
  19. {
  20. $out = "GET $target HTTP/1.1\r\n";
  21. $out .= "Host: $host\r\n";
  22. $out .= "Cookie: ASPSESSIONIDSQTBQSDA=DFCAPKLBBFICDAFMHNKIGKEG\r\n";
  23. $out .= "Referer: $referer\r\n";
  24. $out .= "Connection: Close\r\n\r\n";
  25. fwrite($fp, $out);
  26. while (!feof($fp))
  27. {
  28. echo fgets($fp, 128);
  29. }
  30. fclose($fp);
  31. }
复制代码

网页代码, PHP


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn