私は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!
}
}
?>
End note:ウェブサイトをスクラップするには、 "Scripts"フォルダ内に作成されたすべてのクラスをコール/インスタンス化する必要があります。私の疑問は、約100のクラスをインスタンス化する最良の方法です。
私にこれをどう設計するかの手がかりを与えることができれば。
最高のお礼、
申し訳ありません。
* [HTMLを解析するための最善の方法](http://stackoverflow.com/questions/3577641/best-methods-to-parse-html/3577662#3577662)があります。 – Gordon
あなたはいつもページから同じものを削りますか?常にリンク、タイトルなど?さまざまなクライアント(Google、Yahoo、StackOverflow)はどういう点で違いますか? – Gordon
@ Gordon、特定の情報を持つページがあります。処理するメソッドは "Scripts"フォルダ内にあります。 –