2017-10-30 3 views
-2

다음 사이트의 배열에있는 부드러운 정보 (부서, 위치, 참조 번호, 마감일, 설명 및 부드러운 파일 용 URL (첨부 파일/다운로드 가능한 pdf))를 구문 분석하려고합니다. http://www.biman-airlines.com/corporate/tenderHTML로 PHP 구문 분석

나는 초보자이며 어떻게 해야할지 모릅니다. 내가

<?php 
$url = "http://www.biman-airlines.com/corporate/tender"; 
$ch = curl_init(); 
$timeout = 5; 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 
$html = curl_exec($ch); 
curl_close($ch); 

$dom = new DOMDocument(); 

@$dom->loadHTML($html); 

$xpath = new DomXPath($dom); 


$headerNames = array(); 
foreach ($xpath->query('//table[@id=""]//th') as $node) { 
$headerNames[] = $node->nodeValue; 
} 


$data = array(); 
foreach ($xpath->query('//tbody[@id=""]//tr') as $node) { 
$rowData = array(); 
foreach ($xpath->query('td', $node) as $cell) { 
    $rowData[] = $cell->nodeValue; 
} 

$data[] = array_combine($headerNames, $rowData); 
} 

print_r($data); 
?> 
+0

제발 좀 더 많은 정보를 공유하십시오. 어떤 오류가 있었으며 무엇을 수정하려고 시도 했습니까? –

답변

-2
<!doctype html> 
<html lang="en"> 
<head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
    <meta name="description" content="Showcases a horizontal menu that hides at 
    small window widths, and which scrolls when revealed."> 
    <title>Responsive Horizontal-to-Scrollable Menu &ndash; Layout Examples &ndash; Pure</title> 

    <link rel="stylesheet" href="https://unpkg.com/[email protected]/build/pure-min.css" integrity="sha384-nn4HPE8lTHyVtfCBi5yW9d20FjT8BJwUXyWZT9InLYax14RDjBj46LmSztkmNP9w" crossorigin="anonymous"> 


    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/lib 
    <!--[if lt IE 9]> 
     <script src="http://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7/html5shiv.js"></script> 
    <![endif]--> 
    <script> 
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ 
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), 
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) 
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); 

    ga('create', 'UA-41480445-1', 'purecss.io'); 
    ga('send', 'pageview'); 
    </script> 
</head> 
<body> 





<style> 
.custom-menu-wrapper { 
    background-color: white<!--#808080-->; 
    margin-bottom: 2.5em; 
    white-space: nowrap; 
    position: fixed; 
} 

.custom-menu { 
background-color: white; 
    display: inline-block; 
    width: auto; 
    vertical-align: middle; 
    -webkit-font-smoothing: antialiased; 
} 

.custom-menu .pure-menu-link, 
.custom-menu .pure-menu-heading { 
    color: black; 
} 

.custom-menu .pure-menu-link:hover, 
.custom-menu .pure-menu-heading:hover { 
    background-color: transparent; 
} 

.custom-menu-top { 
    position: relative; 
    padding-top: .5em; 
    padding-bottom: .5em; 
} 

.custom-menu-brand { 
    display: block; 
    text-align: center; 
    position: relative; 
} 

.custom-menu-toggle { 
    width: 44px; 
    height: 44px; 
    display: block; 
    position: absolute; 
    top: 3px; 
    right: 0; 
    display: none; 
} 

.custom-menu-toggle .bar { 
    background-color: black; 
    display: block; 
    width: 20px; 
    height: 2px; 
    border-radius: 100px; 
    position: absolute; 
    top: 22px; 
    right: 12px; 
    -webkit-transition: all 0.5s; 
    -moz-transition: all 0.5s; 
    -ms-transition: all 0.5s; 
    transition: all 0.5s; 
} 

.custom-menu-toggle .bar:first-child { 
    -webkit-transform: translateY(-6px); 
    -moz-transform: translateY(-6px); 
    -ms-transform: translateY(-6px); 
    transform: translateY(-9px); 
} 

.custom-menu-toggle.x .bar { 
    -webkit-transform: rotate(45deg); 
    -moz-transform: rotate(45deg); 
    -ms-transform: rotate(45deg); 
    transform: rotate(45deg); 
} 

.custom-menu-toggle.x .bar:first-child { 
    -webkit-transform: rotate(-45deg); 
    -moz-transform: rotate(-45deg); 
    -ms-transform: rotate(-45deg); 
    transform: rotate(-45deg); 
} 

.custom-menu-screen { 
    background-color:white; 
    -webkit-transition: all 0.5s; 
    -moz-transition: all 0.5s; 
    -ms-transition: all 0.5s; 
    transition: all 0.5s; 
    height: 3em; 
    width: 100%; 
    position: absolute; 
    top: 0; 
    z-index: -1; 
} 

.custom-menu-tucked .custom-menu-screen { 
    -webkit-transform: translateY(-44px); 
    -moz-transform: translateY(-44px); 
    -ms-transform: translateY(-44px); 
    transform: translateY(-44px); 
} 
.sizee{ 
    width: 10%; 
    margin-top: -1%; 
    margin-bottom: -1%; 
    } 
@media (max-width: 90em) { 

    .custom-menu { 
     display: block; 

    } 

    .custom-menu-toggle { 
     display: block; 
     display: none\9; 
    } 

    .custom-menu-bottom { 
     position: absolute; 
     width: 100%; 
     border-top: 1px solid #eee; 
     background-color: white\9; 
     z-index: 100; 
    } 

    .custom-menu-bottom .pure-menu-link { 
     opacity: 1; 
     -webkit-transform: translateX(0); 
     -moz-transform: translateX(0); 
     -ms-transform: translateX(0); 
     transform: translateX(0); 
     -webkit-transition: all 0.5s; 
     -moz-transition: all 0.5s; 
     -ms-transition: all 0.5s; 
     transition: all 0.5s; 
    } 

    .custom-menu-bottom.custom-menu-tucked .pure-menu-link { 
     -webkit-transform: translateX(-140px); 
     -moz-transform: translateX(-140px); 
     -ms-transform: translateX(-140px); 
     transform: translateX(-140px); 
     opacity: 0; 
     opacity: 1\9; 
    } 

    .pure-menu-horizontal.custom-menu-tucked { 
     z-index: -1; 
     top: 45px; 
     position: absolute; 
     overflow: hidden; 
    } 
} 
    @media (max-width: 60em) { 
    .sizee{ 
    width: 25%; 
    margin-top: -1%; 
    margin-bottom: -1%; 
    } 
    } 

</style> 
<div> 
<div class="custom-menu-wrapper navbar-fixed-top"> 
    <div class="pure-menu custom-menu custom-menu-top"> 
     <a href="" class="pure-menu-heading custom-menu-brand"><img class="sizee" src='bhagat.jpg'></a> 
     <a href="#" class="custom-menu-toggle" id="toggle"><s class="bar"></s><s class="bar"></s></a> 
    </div> 
    <div class="pure-menu pure-menu-horizontal pure-menu-scrollable custom-menu custom-menu-bottom custom-menu-tucked" id="tuckedMenu" style='border: inherit;'> 
     <div class="custom-menu-screen"></div> 
     <center> 
     <ul class="pure-menu-list"> 
      <li class="pure-menu-item"><a href="#" class="pure-menu-link">Home</a></li> 
      <li class="pure-menu-item"><a href="#" class="pure-menu-link">About</a></li> 
      <li class="pure-menu-item"><a href="#" class="pure-menu-link">Contact</a></li> 
      <li class="pure-menu-item"><a href="#" class="pure-menu-link">Blog</a></li> 
      <li class="pure-menu-item"><a href="#" class="pure-menu-link">GitHub</a></li> 
      <li class="pure-menu-item"><a href="#" class="pure-menu-link">Twitter</a></li> 
      <li class="pure-menu-item"><a href="#" class="pure-menu-link">Apple</a></li> 
      <li class="pure-menu-item"><a href="#" class="pure-menu-link">Google</a></li> 
      <li class="pure-menu-item"><a href="#" class="pure-menu-link">Wang</a></li> 
      <li class="pure-menu-item"><a href="#" class="pure-menu-link">Yahoo</a></li> 
      <li class="pure-menu-item"><a href="#" class="pure-menu-link">W3C</a></li> 
     </ul> 
     </center> 
    </div> 
</div> 
</div> 
<script> 
(function (window, document) { 
document.getElementById('toggle').addEventListener('click', function (e) { 
    document.getElementById('tuckedMenu').classList.toggle('custom-menu-tucked'); 
    document.getElementById('toggle').classList.toggle('x'); 
}); 
})(this, this.document); 
</script> 


<style> 
.main { 
    padding: 2em; 
    color: black; 
} 
</style> 

<div class="main"> 
</div> 


</body> 
</html> 
0

이 시도 작동하지 않는 경우 다음을 시도했다. 도움이되는지 확인하십시오.

$url = "http://www.biman-airlines.com/corporate/tender"; 

    /* Use internal libxml errors -- turn on in production, off for debugging */ 
    libxml_use_internal_errors(true); 
    /* Createa a new DomDocument object */ 
    $dom = new DomDocument; 
    /* Load the HTML */ 
    $dom->loadHTMLFile($url); 
    /* Create a new XPath object */ 
    $xpath = new DomXPath($dom); 
    /* Query all <td> nodes containing specified class name */ 
    $nodes = $xpath->query("//th"); 
    /* Set HTTP response header to plain text for debugging output */ 
    // header("Content-type: text/plain"); 

    /* Traverse the DOMNodeList object to output each DomNode's nodeValue */ 
    foreach ($nodes as $i => $node) { 
     if(($i % 10) == 0) 
     echo "Node($i): ", $node->nodeValue, "\n" . "<br>"; 
    } 
+0

은 완벽하게 작동합니다. 정말 고맙습니다. 배열에서 노드 값을 어떻게 나눌 수 있습니까? 노드 0에서와 같이 ------ 노드 (0) : 1 부서 : 기업 기획 위치 : 다카 Ref.No : DACPM/Q400/173/2017/529 마감일 : 21 NOV 2017 ---- this from i want 부서, 위치, refno 및 종료 날짜를 데이터베이스에 삽입 할 배열 변수로 유지합니다. - –

+0

폭발을 사용하십시오. 또는 배열의 다른 요소를 % 10없이 봅니다. 그게 당신에게 세부 사항들을 줄 수 있어요. 대답을 좋아하면 upvote를하십시오. –

+0

어떻게하면 $ nodes 아래의 설명 부분과 URL을 잡을 수 있습니까 ?? 대단히 감사합니다. –