大家经常会想监控一些特殊信息,比如促销信息或者啥的,想到之前写的一些代码,拿出来和大家分享一下,也是做个记录了。我写的是监控ds特价机的页面代码,贴出全部代码,其实就是个简单的正则匹配,不过我不是很懂,写的也不好,大家可以改进留言给我。另外如果有兴趣的朋友可以再增加下在有货情况下的自动邮件发送哦。
1 <!DOCTYPE html> 2 <html xmlns="http://www.w3.org/1999/xhtml" dir='ltr'> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <title>DirectSpace OVZ 768MB 年付15美元 VPS 检测系统</title> 6 <style type="text/css"> 7 html { 8 background: #f9f9f9; 9 } 10 body { 11 background: #fff; 12 color: #333; 13 font-family: sans-serif; 14 margin: 2em auto; 15 padding: 1em 2em; 16 -webkit-border-radius: 3px; 17 border-radius: 3px; 18 border: 1px solid #dfdfdf; 19 max-width: 700px; 20 height: 600px; 21 } 22 h1 { 23 border-bottom: 1px solid #dadada; 24 clear: both; 25 color: #666; 26 font: 24px Georgia, "Times New Roman", Times, serif; 27 margin: 30px 0 0 0; 28 padding: 0; 29 padding-bottom: 7px; 30 } 31 #index { 32 margin-top: 50px; 33 } 34 #index p { 35 font-size: 14px; 36 line-height: 1.5; 37 margin: 25px 0 20px; 38 } 39 ul li { 40 margin-bottom: 10px; 41 font-size: 12px ; 42 } 43 a { 44 color: #21759B; 45 text-decoration: none; 46 } 47 a:hover { 48 color: #D54E21; 49 } 50 .button { 51 display: inline-block; 52 text-decoration: none; 53 font-size: 14px; 54 line-height: 23px; 55 height: 24px; 56 margin: 0; 57 padding: 0 10px 1px; 58 cursor: pointer; 59 border-width: 1px; 60 border-style: solid; 61 -webkit-border-radius: 3px; 62 border-radius: 3px; 63 white-space: nowrap; 64 -webkit-box-sizing: border-box; 65 -moz-box-sizing: border-box; 66 box-sizing: border-box; 67 background: #f3f3f3; 68 background-image: -webkit-gradient(linear, left top, left bottom, from(#fefefe), to(#f4f4f4)); 69 background-image: -webkit-linear-gradient(top, #fefefe, #f4f4f4); 70 background-image: -moz-linear-gradient(top, #fefefe, #f4f4f4); 71 background-image: -o-linear-gradient(top, #fefefe, #f4f4f4); 72 background-image: linear-gradient(to bottom, #fefefe, #f4f4f4); 73 border-color: #bbb; 74 color: #333; 75 text-shadow: 0 1px 0 #fff; 76 } 77 78 .button.button-large { 79 height: 29px; 80 line-height: 28px; 81 padding: 0 12px; 82 } 83 84 .button:hover, 85 .button:focus { 86 background: #f3f3f3; 87 background-image: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#f3f3f3)); 88 background-image: -webkit-linear-gradient(top, #fff, #f3f3f3); 89 background-image: -moz-linear-gradient(top, #fff, #f3f3f3); 90 background-image: -ms-linear-gradient(top, #fff, #f3f3f3); 91 background-image: -o-linear-gradient(top, #fff, #f3f3f3); 92 background-image: linear-gradient(to bottom, #fff, #f3f3f3); 93 border-color: #999; 94 color: #222; 95 } 96 97 .button:focus { 98 -webkit-box-shadow: 1px 1px 1px rgba(0,0,0,.2); 99 box-shadow: 1px 1px 1px rgba(0,0,0,.2); 100 } 101 102 .button:active { 103 outline: none; 104 background: #eee; 105 background-image: -webkit-gradient(linear, left top, left bottom, from(#f4f4f4), to(#fefefe)); 106 background-image: -webkit-linear-gradient(top, #f4f4f4, #fefefe); 107 background-image: -moz-linear-gradient(top, #f4f4f4, #fefefe); 108 background-image: -ms-linear-gradient(top, #f4f4f4, #fefefe); 109 background-image: -o-linear-gradient(top, #f4f4f4, #fefefe); 110 background-image: linear-gradient(to bottom, #f4f4f4, #fefefe); 111 border-color: #999; 112 color: #333; 113 text-shadow: 0 -1px 0 #fff; 114 -webkit-box-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, 0.5 ); 115 box-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, 0.5 ); 116 } 117 118 .d1{max-width: 700px;;min-height:20px;float:left;} 119 120 .d2{width:350px;min-height:40px;float:left;} 121 122 .d3{width:350px;min-height:40px;float:left;} 123 124 </style> 125 </head> 126 <body id="index"> 127 <p><h1>DirectSpace OVZ 768MB 年付15美元 VPS “存货检测” by 海浪</h1></p> 128 <p><h2><?php 129 130 date_default_timezone_set('Asia/Chongqing'); 131 //系统时间差8小时问题 132 133 $now = getdate(time()); 134 $cur_wday=$now['wday']; 135 $date = date("Y-m-d H:i:s $cweekday[$cur_wday]"); 136 echo $date; 137 138 ?><br /><font color='red'> 139 140 <?php 141 $url = "https://eportal.directspace.net/cart.php?gid=22"; 142 $contents = file_get_contents($url); 143 //如果出现中文乱码使用下面代码 144 145 //$getcontent = iconv("gb2312", "utf-8",$contents); 146 147 //echo $contents; 148 149 preg_match_all("|<[^>]+>\((.*)\)</[^>]+>|U",$contents,$arr); 150 echo "<br>"; 151 if($arr[1][0]>0) 152 echo "有库存哦".$arr[1][0]; 153 else 154 echo "没有库存哦"; 155 ?> 156 157 </font><br /><a href="http://eportal.directspace.org/cart.php?a=add&gid=22" class="button button-large" target="_blank">点击查看最新存货</a></h2> 注意:填写虚假购买信息有可能导致订单被定为欺诈,建议用不那么假的地址等信息<hr /></p> 158 159 </body> 160 </html>