2015-07-21 78 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],你会什么脚本生成它,