https://bigfuture.collegeboard.org/college-university-search/dickinson-college
我试图使用 PHP 的 preg_match
函数获取此页面的内容:
$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);
我想要获取的信息位于类为“clearfix margin60 marginBottomOnly”的 div 中。
在 Chrome 中使用 Firebug 或“检查元素”时,此 div 中的内容是可见的。 然而,当我查看页面源代码时,div 是空的。
谁能告诉我原因以及如何从页面中获取我想要的内容(例如,学校的位置)?
最佳答案
你看不到它是因为内容是由 JavaScript 函数生成的,如果你将检查“脚本”选项卡并查找 div 名称 [ gwtDiv ],你将看到生成它的脚本,
关于javascript - 无法使用 PHP 从 CollegeBoard 获取内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31536325/