我想構建一個我的個人項目,但是當我使用簡單的HTML DOM類時,我有點卡住了。PHP簡單的HTML DOM刮擦外部URL
我想要做的是刮一個網站,並檢索所有的內容,它是內部的HTML,匹配某個類。
到目前爲止我的代碼是:
<?php
error_reporting(E_ALL);
include_once("simple_html_dom.php");
//use curl to get html content
$url = 'http://www.peopleperhour.com/freelance-seo-jobs';
$html = file_get_html($url);
//Get all data inside the <div class="item-list">
foreach($html->find('div[class=item-list]') as $div) {
//get all div's inside "item-list"
foreach($div->find('div') as $d) {
//get the inner HTML
$data = $d->outertext;
}
}
print_r($data)
echo "END";
?>
所有我這個得到的是「END」,沒有別的輸出都一個空白頁。
[Scrape web page contents]的可能重複(http://stackoverflow.com/questions/584826/scrape-web-page-contents) –