1
https://bigfuture.collegeboard.org/college-university-search/dickinson-college無法使用PHP
我試圖使用PHP的preg_match
函數來獲取這個頁面的內容從CollegeBoard獲取內容:
$filename = 'https://bigfuture.collegeboard.org/college-university-search/dickinson-college';
$content = file_get_contents($filename);
$subject = $content;
$pattern = '#(?<=<span class="locality" itemprop="addressLocality">)(\w*)(?=<\/span>)#';
preg_match($pattern,$subject,$city);
print_r($city);
,我想獲取的信息是中div與類「clearfix margin60 marginBottomOnly」。
當使用螢火蟲或「檢查元素」在Chrome中,這個div內的內容是可見的。 但是當我查看頁面源時,div是空的。
有人能告訴我理由以及如何從頁面獲取我想要的內容(例如,學校的位置)嗎?
你練正則表達式,你需要這樣做?用DOMDocument獲取HTML內容要容易得多 – Daimos
您可以推薦我一些資源來閱讀關於如何使用DOMDocument獲取HTML內容的更多信息? –
很多信息你甚至可以在這裏找到,但如果你想快速簡單的工作,我個人使用simplehtmldom,檢查它:http://simplehtmldom.sourceforge.net/ – Daimos