大二学了一下PHP cURL,做了几个demo。
1、代码如下:
index.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>域名备案查询</title>
<style type="text/css">
*{margin: 0;padding: 0;border: 0;}
body{font-family: 微软雅黑;width: 100%;background-color: #f8f8f8}
@media (max-width: 450px){
.domain_check_form{
width: 100%;
height: 500px;
margin: 0 auto;
background-color: ;
}
}
@media (min-width: 450px){
.domain_check_form{
width: 100%;
max-width: 600px;
height: 800px;
margin: 0 auto;
background-color: #f8f8f8;
}
}
form input{
outline: none;
font-family: 微软雅黑;
font-size: 16px;
transition: all .5s ease;
}
form input:focus {
border-color: rgba(82, 168, 236, 0.8);
outline: thin dotted \9;
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(82, 168, 236, 0.6);
}
p{padding: 10px 0 0 0;text-align: center;}
.query_domain{
width: 90%;
height: 40px;
padding-left: 5%;/*设置placeholder的位置*/
}
.submit{
width: 90%;
height: 50px;
color: #fff;
font-size: 16px;
background-color: rgb(14,81,83);
transition: all .5s ease;
font-family: 微软雅黑;
}
.submit:hover{
background-color: rgb(30,151,152);
}
/*input placeholder样式*/
:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
opacity:.5;
}
::-moz-placeholder { /* Mozilla Firefox 19+ */
opacity:.5;
}
input:-ms-input-placeholder{
opacity:.5;
}
input::-webkit-input-placeholder{
opacity:.5;
}
input::-webkit-input-placeholder { /* WebKit browsers*/
opacity:.5;
}
input:-moz-placeholder { /* Mozilla Firefox 4 to 18*/
opacity:.5;
}
input::-moz-placeholder { /* Mozilla Firefox 19+*/
opacity:.5;
}
input:-ms-input-placeholder { /* Internet Explorer 10+*/
opacity:.5;
}
</style>
</head>
<body>
<form class="domain_check_form" method="get" action="query_domain.php">
<p>
<input class="query_domain" name="domain" type="text"/ required="" placeholder="facebook.com">
</p>
<p>
<input class="submit" name="submit" type="submit" value="查询"/>
</p>
<p align="center" style="font-size: 12px;margin-top: 50px;">by Vegeta</p>
</form>
</body>
</html>
query_domain.php
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<style type="text/css">
*{margin: 0;padding: 0;border: 0;font-family: 微软雅黑;}
body{background-color: #e9e9e9;}
@media (min-width: 450px){
.result_box{
width: 100%;
max-width: 600px;
height: 800px;
margin: 0 auto;
background-color: #e9e9e9;
}
}
.result_p0{
width: 95%;
height: 60px;
display: block;
padding-left: 5%;
line-height: 30px;
font-size: 14px;
background-color: #e9e9e9;
transition: background-color .5s ease;
}
.result_p0:hover{
background-color: #fff;
}
.result_p1{
width: 95%;
height: 60px;
display: block;
padding-left: 5%;
line-height: 30px;
font-size: 14px;
background-color: #f5f5f5;
transition: background-color .5s ease;
}
.result_p1:hover{
background-color: #fff;
}
.result_s{font-size: 12px;text-align: center;}
</style>
<?php
header("Content-type:text/html,charset=utf8");
error_reporting(0);
include('simple_html_dom.php');
$domain=$_GET['domain'];
$url='http://www.beianbeian.com/search/'.$domain;
$ch = curl_init();
for($i=0;$i<1;$i++)
{
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);// 这个是主要参数
$output = curl_exec($ch) ;
$html = new simple_html_dom();
$html ->load($output);
// print_r($output);
curl_close($ch);
// var_dump($output);
$arrMsg = array();
foreach($html->find('tbody tr td') as $m) {
array_push($arrMsg,$m->plaintext);
}
if($arrMsg[0]==1) {
echo<<<begin
<body>
<div class="result_box">
<br/>
<p class="result_p1">序号: $arrMsg[0]</p>
<p class="result_p0">主办单位名称: $arrMsg[1]</p>
<p class="result_p1">主办单位性质: $arrMsg[2]</p>
<p class="result_p0">网站备案/许可证号: $arrMsg[3]</p>
<p class="result_p1">网站名称: $arrMsg[4]</p>
<p class="result_p0">网站首页网址: $arrMsg[5]</p>
<p class="result_p1">审核时间: $arrMsg[6]</p>
<p class="result_p0">是否限制接入 : $arrMsg[7]</p>
<br/><br/>
<p class="result_s">以上数据来之站长之家</p>
</div>
</body>
begin;
break;
}
else{
echo<<<begin
<div class="result_box">
<br/>
<p align="center">您输入的域名未备案或者备案取消-_-!!</p>
</div>
begin;
break;
}
}
?>
simple_html_dom.php
需要下载php解析html类库:simple_html_dom.php
2、效果截图
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/151240.html