我正在尝试使用 PHP simplehtmldom 库获取该网站的内容。
http://www.immigration.govt.nz/migrant/stream/work/workingholiday/czechwhs.htm "
它不起作用,所以我尝试使用 CURL:
function curl_get_file_contents($URL)
{
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $URL);
$contents = curl_exec($c);
curl_close($c);
if ($contents) return $contents;
else return FALSE;
}
但总是只得到一些 JS 代码和内容的响应:
<noscript>Please enable JavaScript to view the page content.</noscript>
是否有可能使用 PHP 解决此问题?在这种情况下我必须使用 PHP,所以我需要模拟基于 JS 的浏览器。
非常感谢您的任何建议。
最佳答案
I must use PHP in this case so i need to simulate JS based browser.
我推荐两种方式:
- 杠杆 v8js php plugin抓取时处理网站的js。参见 here一个用法示例。
- 通过使用 Selenium 模拟基于 JS 的浏览器 , iMacros 或 webRobots.io Chrome 分机。但在这种情况下,您脱离了 PHP 脚本。
关于javascript - PHP:如何基于 Javascript 抓取网站内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28884428/