<?php
//header("Content-Type:text/html;charset=gb2312");
header("Content-type:text/html;charset=gb2312");
include('simple_html_dom.php');//引入类库文件
function getUrlRes($url,$headers){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_PROXY, "http://proxynj.zte.com.cn:80");
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$data = curl_exec($curl);
curl_close($curl);
return $data;
}
function printWebUrl($url){
echo '<a href= '. $url.'>'. $url .' </a> <br />';
}
function parseJsjszpw($html){
$divs = $html->find('#cnzp3 ul li');
foreach ($divs as $value)
{
$str = $value->children[2]->nodes[0]->_[4];
$str = mb_convert_encoding($str, 'utf-8', 'gbk');
if ( strpos($str,'南京') != false && ( strpos($str,'中学') != false
|| strpos($str,'小学') != false ) )
{
echo ": " .$value->children[2]->nodes[0]->_[4] . "<br />";
}
}
$html->clear();
}
$headers = array(
'User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36',
'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'Accept-Encoding:gzip, deflate',
'Accept-Language:zh-CN,zh;q=0.8',
'Cache-Control:max-age=0',
'Proxy-Connection:keep-alive',
);
$url ="http://www.jsjszpw.com/";
$urlResp = getUrlRes($url, $headers);
$html = str_get_html($urlResp);
printWebUrl($url);
parseJsjszpw($html);
?>