【发布时间】:2017-02-15 09:44:18
【问题描述】:
有人可以帮助我如何通过 curl 解析此链接吗?
https://www.linkedin.com/in/williamhgates/
这是我的代码:
运行一下看看结果:
$url = "https://www.linkedin.com/in/williamhgates/";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: www.linkedin.com/in/williamhgates/'));
$output = curl_exec($ch);
curl_close($ch);dd($output);die;
我只想在一个文件中获取整个源代码,但它显示:
Could not process this client request HTTP method request for URL
【问题讨论】:
-
可能缺少像 useragents 这样的标头。
-
我用 html_dom 和 curl 尝试了不同的方法,但它们都不起作用!
-
如果您在 php.ini 中启用了 file_get_html,您可以使用
$html = file_get_html(https://www.linkedin.com/in/williamhgates/');并使用 DOM 类从中提取数据。 -
我之前尝试过,但我根本无法获得源代码。
标签: php html-parsing