<?php
require('phpQuery/phpQuery.php');
$link = "http://news.163.com/19/0131/15/E6S1OSOL000189DH.html";
/*function curl_get($url, $gzip=false){
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
if($gzip) curl_setopt($curl, CURLOPT_ENCODING, "gzip"); // 关键在这里
$content = curl_exec($curl);
curl_close($curl);
return $content;
}
$content = curl_get($link,$gzip=false);*/
$content = file_get_contents($link);
$content = iconv("gb2312", "utf-8//IGNORE", $content);
phpQuery::newDocumentFile($content); //以 html 内容的方式进行初始化
$title = pq(".post_content_main h1")->text();
var_dump($title);
?>
获取之后,显示如下
Warning: file_get_contents(<!DOCTYPE HTML> <!--[if IE 6 ]> <html id="ne_wrap" class="ne_ua_ie6 ne_ua_ielte8"> <![endif]--> <!--[if IE 7 ]> <html id="ne_wrap" class="ne_ua_ie7 ne_ua_ielte8"> <![endif]--> <!--[if IE 8 ]> <html id="ne_wrap" class="ne_ua_ie8 ne_ua_ielte8"> <![endif]--> <!--[if IE 9 ]> <html id="ne_wrap" class="ne_ua_ie9"> <![endif]--> <!--[if (gte IE 10)|!(IE)]><!--> <html id="ne_wrap"> <!--<![endif]--> <head> <title>网易哒哒:用更短的时间,带你看更酷的世界_网易新闻</title> <base target="_blank"/><!--[if lte IE 6]></base><![endif]--> <meta http-equiv="expires" content="0"/> <meta http-equiv="Cache-Control" content="no-transform"/> <meta http-equiv="Cache-Control" cont in D:\xin\phpStudy\PHPTutorial\www\php_learn\phpquery\phpQuery\phpQuery.php on line 408
string(0) ""
我只是想要 网易哒哒:用更短的时间,带你看更酷的世界 这个文章标题
非常感谢
require('phpQuery/phpQuery.php');
$link = "http://news.163.com/19/0131/15/E6S1OSOL000189DH.html";
/*function curl_get($url, $gzip=false){
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
if($gzip) curl_setopt($curl, CURLOPT_ENCODING, "gzip"); // 关键在这里
$content = curl_exec($curl);
curl_close($curl);
return $content;
}
$content = curl_get($link,$gzip=false);*/
$content = file_get_contents($link);
$content = iconv("gb2312", "utf-8//IGNORE", $content);
phpQuery::newDocumentFile($content); //以 html 内容的方式进行初始化
$title = pq(".post_content_main h1")->text();
var_dump($title);
?>
获取之后,显示如下
Warning: file_get_contents(<!DOCTYPE HTML> <!--[if IE 6 ]> <html id="ne_wrap" class="ne_ua_ie6 ne_ua_ielte8"> <![endif]--> <!--[if IE 7 ]> <html id="ne_wrap" class="ne_ua_ie7 ne_ua_ielte8"> <![endif]--> <!--[if IE 8 ]> <html id="ne_wrap" class="ne_ua_ie8 ne_ua_ielte8"> <![endif]--> <!--[if IE 9 ]> <html id="ne_wrap" class="ne_ua_ie9"> <![endif]--> <!--[if (gte IE 10)|!(IE)]><!--> <html id="ne_wrap"> <!--<![endif]--> <head> <title>网易哒哒:用更短的时间,带你看更酷的世界_网易新闻</title> <base target="_blank"/><!--[if lte IE 6]></base><![endif]--> <meta http-equiv="expires" content="0"/> <meta http-equiv="Cache-Control" content="no-transform"/> <meta http-equiv="Cache-Control" cont in D:\xin\phpStudy\PHPTutorial\www\php_learn\phpquery\phpQuery\phpQuery.php on line 408
string(0) ""
我只是想要 网易哒哒:用更短的时间,带你看更酷的世界 这个文章标题
非常感谢