PHP crawl web page code example

WBOY
Release: 2016-07-25 08:46:10
Original
1052 people have browsed it
  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.1rn";
  21. $out .= "Host: $hostrn";
  22. $out .= "Cookie: ASPSESSIONIDSQTBQSDA=DFCAPKLBBFICDAFMHNKIGKEGrn";
  23. $out .= "Referer: $refererrn";
  24. $out .= "Connection: Closernrn";
  25. fwrite($fp, $out);
  26. while (!feof($fp))
  27. {
  28. echo fgets($fp, 128);
  29. }
  30. fclose($fp);
  31. }
复制代码

网页代码, PHP


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template