|
@@ -14,7 +14,8 @@ class Weather extends Base
|
|
|
//仁化 101280206
|
|
|
//清远 101281301
|
|
|
//北京 101010100
|
|
|
- $url = "http://www.weather.com.cn/weather/101280201.shtml";
|
|
|
+ $cityNo=input("city","101280206");
|
|
|
+ $url = "http://www.weather.com.cn/weather/".$cityNo.".shtml";
|
|
|
// $ql=QueryList::getInstance()->get($url);
|
|
|
$options=[
|
|
|
'headers' => [
|
|
@@ -38,8 +39,13 @@ class Weather extends Base
|
|
|
|
|
|
// exit;
|
|
|
$ql = QueryList::getInstance()->html($html);
|
|
|
- $html7d = $ql->find("#7d>.t")->html();
|
|
|
- var_dump($html7d);
|
|
|
+ $city=$ql->find(".crumbs")->text();
|
|
|
+ $city=str_replace(" ","",$city);
|
|
|
+ $city=str_replace("\r","",$city);
|
|
|
+ $city=str_replace("\t","",$city);
|
|
|
+ $city=str_replace("\n","",$city);
|
|
|
+// $html7d = $ql->find("#7d>.t")->html();
|
|
|
+// var_dump($html7d);
|
|
|
//$ql = QueryList::getInstance()->html($html7d);
|
|
|
//var_dump($html7d);
|
|
|
// $resList=$ql->find("li")->getElements();
|
|
@@ -49,13 +55,18 @@ class Weather extends Base
|
|
|
// }
|
|
|
$rules = [
|
|
|
"title" => ["h1", "text"],
|
|
|
- "wea" => [".wea", "text"],
|
|
|
+ "weather" => [".wea", "text"],
|
|
|
"max"=>[".tem>span","text"],
|
|
|
"min"=>[".tem>i","text"],
|
|
|
];
|
|
|
$range = '#7d>ul>li';
|
|
|
- $res = $ql->rules($rules)->range($range)->query()->getData();
|
|
|
- print_r($res);
|
|
|
+ $weather = $ql->rules($rules)->range($range)->query()->getData()->toArray();
|
|
|
+ $res=[
|
|
|
+ "city"=>$city,
|
|
|
+ "weather"=>$weather
|
|
|
+ ];
|
|
|
+ $this->success($res);
|
|
|
+// print_r($res);
|
|
|
/* $resList=$ql->find("li")->eq(0)->html();
|
|
|
var_dump($resList);
|
|
|
$resList=$ql->find("li")->eq(1)->html();
|