2016-07-20 2 views
-1

나는 PHP로 신입 회원입니다. 내가 뭘 하려는지는 페이지 매김의 링크를 가져 오는 것입니다. 페이지에 페이지 매김이 있으며 페이지를 선택할 때 경로가 변경됩니다. http://ahadith.co.uk/sahihmuslim.php 인 메인 페이지에 머물러서 페이지의 URL을 가져 오는 방법은 무엇입니까?페이지 매김 링크 가져 오기

<?php 
     $ch = curl_init(); 
     curl_setopt($ch, CURLOPT_URL, "http://ahadith.co.uk/sahihmuslim.php"); 
//fetches data from the site mentioned above 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     $output = curl_exec($ch); 

     $pattern = "/href=[']([^'][a-zA-Z]+.[a-zA-Z]+.[cid]+=[0-9]+)[']?/"; 
//this regex brings the links from the above url 
     preg_match_all($pattern, $output, $matches, PREG_PATTERN_ORDER); 
     foreach ($matches[1] as $data) { 
     $homepage = file_get_contents('http://ahadith.co.uk/'.$data); 
//all the links data which was caught above using regex has been stored in $homepage 
     $pattern_chapter= "/(?<=\<h2\>)(\s*.*\s*)(?=\<\/h2\>)/"; 
//Here I have fetched the chapters from the data stored in $homepage 
     preg_match_all($pattern_chapter, $homepage, $matches_chapter, PREG_PATTERN_ORDER); 
     foreach ($matches_chapter[1] as $chapters) { 
     print_r($chapters); 
     } 
?> 

지금 내가 $homepage에 저장된 데이터의 페이지 매김의 링크를 얻을 수 있습니다. 이 경우 페이지 매김에는 44 페이지가 있고 나는 44 페이지 전부의 연결을 얻고 싶다. 이것은 페이지 매김에있는 링크들과 일치하는 정규 표현식입니다. http:\/\/([a-zA-Z]+.[a-zA-Z]+.[a-zA-Z]+.[a-zA-Z]+.[a-zA-Z]+.[cid]+=[0-9]&[a-zA-Z]+=[0-9]&[a-zA-Z]+=[0-9]+) 나는 이것에 대한 많은 장소를 수색했지만 이것과 관련된 것을 찾을 수 없습니다. 제발 아무도 이걸 도와 줄 수 없어요.

답변

0

"HtmlPageDom"을 사용하십시오. DOM을 사용하여 HTML 문서를 쉽게 조작 할 수있는 타사 라이브러리입니다. 어떤 페이지에서 원하는 데이터를 추출 할 수 있습니다. 이를 위해

https://github.com/wasinger/htmlpagedom/blob/master/README.md

+0

내가 모든 것을 다시 시작해야합니다, 내가 매김에서 링크를 얻기 위해 여기에 사용할 수있는 다른 방법이 있습니까? –

관련 문제