本文共 768 字,大约阅读时间需要 2 分钟。
1.获取新闻列表
//引入phpQueryrequire('/phpQuery/phpQuery.php');
//获取新闻列表信息(假设每条信息都在class为tit下的a标签内,有两种方法获取网页内容)
//获取内容方法1:
$arr=getUrlContent('http://www.xxxxx.org.cn/list.aspx?clmId=102');//getUrlContent为自定义curl函数获取网页内容
phpQuery::newDocument($arr);
//获取内容方法2:
phpQuery::newDocumentFile('http://www.xxxxx.org.cn/list.aspx?clmId=102');
//从内容中筛选信息列表 $contents=pq(".tit >a"); //便利输出每条信息的内容及链接地址 foreach($contents as $k=>$v){ echo pq($v)->html(); echo "<br>"; echo pq($v)->attr("href"); echo "<hr>"; }===================================================
2.获取内容
//引入phpQuery
require('/phpQuery/phpQuery.php');//获取某新闻内容页的新闻内容主体(假设内容在class为articleDetailsText的标签内)
phpQuery::newDocumentFile('http://www.xxxx.gov.cn/Aritcle/576/9017.htm');$content=pq(".articleDetailsText")->html();转载地址:http://gykmf.baihongyu.com/