저는 PHP OOP의 초보자입니다. 이런 종류의 응용 프로그램을 어떻게 구성 할 수 있는지 얻으려고합니다. 이 응용 프로그램은 약 100 개의 다른 웹 사이트를 긁어 모으기위한 것입니다.PHP에서 OOP 응용 프로그램 설계. 어떻게?
나는 모든 다른 웹 사이트의 전역 메서드를 처리하는 "스크랩"이라는 메인 클래스가 있으며, "스크립트"폴더 안에는 내가 고치고있는 웹 사이트의 특정 측면을 처리하기위한 클래스가 있습니다. 외부 라이브러리를 포함하는 "Lib"이라는 다른 폴더가 있습니다. 다음
- Scrap.php
+ Scripts
- Google.php
- Yahoo.php
- Stackoverflow.php
+ Lib
+ libScrap
- LIB_parse.php
+ phpQuery
- phpQuery.php
- others files and folder...
Scrap.php 포함 : :이 파일 스키마를
을 :
<?php
// Includes
require('/lib/libScrap/LIB_parse.php');
require('/lib/phpQuery/phpQuery.php');
// Testing Scrap
$testing = new Scrap;
$testing->teste = $testing->getPage('http://www.yahoo.com','','off');
echo $testing->teste;
class Scrap {
public function __construct() {
// do things!
}
/*
* This method grabs the entire page(HTML) on given URL
* Ex: $htmlgrab->teste = $htmlgrab->getPage('http://testing.com/ofertas/','','off');
* Returns, the HTML of given URL
*/
public function getPage($site, $proxy, $proxystatus) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
if ($proxystatus == 'on') {
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
}
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_URL, $site);
ob_start(); // prevent any output
return curl_exec ($ch); // execute the curl command
ob_end_clean(); // stop preventing output
curl_close ($ch);
}
/*
*
*
*/
public function getLinks() {
// do things!
}
/*
* This method grabs the page title.
* Ex: <title>This is the page title</title>
* Returns, "This is the page title"
*/
public function getTitle() {
// do things!
}
}
?>
을 그리고 폴더 안에 "스크립트"나는 것이다
저를 시각적으로 설명하게 다음과 같은 파일이 있습니다.
<?php
require('../Scrap.php');
class Yahoo extends Scrap {
public function doSomething() {
// do things!
}
}
?>
끝점 : 웹 사이트를 스크랩하기 위해 "스크립트"폴더에 생성 된 모든 클래스를 호출하거나 인스턴스화해야합니다. 내 의심은 약 100 개의 클래스를 인스턴스화하는 가장 좋은 방법에 관한 것입니다.
당신이 나에게 이것을 디자인하는 방법에 대한 단서를 줄 수 있다면.
최고 감사합니다.
죄송합니다.
* (HTML 관련 구문 분석) * (http://stackoverflow.com/questions/3577641/best-methods-to-parse-html/3577662#3577662)입니다. – Gordon
당신은 항상 페이지에서 같은 것을 긁을 것입니까? 항상 링크, 제목 등? 다양한 고객 (Google, Yahoo, StackOverflow)은 어떤면에서 다른가요? – Gordon
@ Gordon, 특정 정보가있는 페이지가있을 것입니다. 처리 할 방법은 "Scripts"폴더 안에 있습니다. –