2015-07-21 100 views
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是空的。

有人能告訴我理由以及如何從頁面獲取我想要的內容(例如,學校的位置)嗎?

+0

你練正則表達式,你需要這樣做?用DOMDocument獲取HTML內容要容易得多 – Daimos

+0

您可以推薦我一些資源來閱讀關於如何使用DOMDocument獲取HTML內容的更多信息? –

+0

很多信息你甚至可以在這裏找到,但如果你想快速簡單的工作,我個人使用simplehtmldom,檢查它:http://simplehtmldom.sourceforge.net/ – Daimos

回答

2

客人不願意看到它,因爲是由JavaScript函數生成的內容,如果u將檢查「腳本」選項卡,並查找div名稱[gwtDiv],你會什麼腳本生成它,