phpquery採集案例

1.獲取新聞列表

//引入phpQuery

require('/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();

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章