天气小偷程序
2019獨角獸企業重金招聘Python工程師標準>>>
例子,php百度天氣小偷程序。
?
復制代碼代碼如下:
<?php //獲取在百度里面搜索 xx(地名)天氣 抓取的天氣信息 $url = "http://www.baidu.com/s?wd=%B1%B1%BE%A9%CC%EC%C6%F8"; //此為在百度里搜 北京天氣 的返回地址 $content = file_get_contents($url); preg_match_all('/<div id="weat">(.+?)<\/table>/si',$content,$temp); preg_match_all('/<td>(.+?)<\/td>/si',$temp[1][0],$temp1); var_dump ($temp1[1][0]);?
輸出信息:
string(243) "北京天氣
今天:溫度22℃ - 24℃。白天:多云, 大陣雨,夜間:多云。東風2級轉1-2級
明天:溫度23℃ - 28℃。白天:多云,夜間:多云。東南風2級"
?
index.php<?php$con = file_get_contents("http://it.sohu.com/s2010/5651/s274087241/index.shtml"); $preg="/·<a href=(.*) target=_blank>(.*)<\/a>/U"; preg_match_all($preg,$con,$arr); foreach($arr[1] as $id=>$v){ echo "<a href=view.php?url=$v>".$arr[2][$id]."</a><br>"; } ?>view.php<?php$con = file_get_contents($_GET[url]); $preg="/<h1>(.*)<\/h1>/"; preg_match($preg,$con,$arr); echo "<h1>".$arr[1]."</h1>"; echo "<hr>"; $preg2="/<div class=\"text clear\" id=\"contentText\" collection=\"Y\">(.*)<\/div>/s"; preg_match($preg2,$con,$arr2); echo $arr2[1];?>?
轉載于:https://my.oschina.net/afengzxf/blog/831078
總結
- 上一篇: 2014百度研发真题及其解析-求比指定数
- 下一篇: Codeforces Round #39