【问题标题】:php get html source code from httpsphp从https获取html源代码
【发布时间】:2012-04-13 08:45:43
【问题描述】:

如何从 https 获取 html 源代码?我尝试使用curl 而不是get_file_contests,但仍然没有得到image src

require dirname(__FILE__) . '/simple_html_dom.php';

$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,'https://www.tumblr.com/');
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_handle, CURLOPT_BINARYTRANSFER, true);
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl_handle, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1");
$query = curl_exec($curl_handle);
curl_close($curl_handle);

$html = file_get_html($query);
foreach($html->find('img') as $element) {
   echo $element->src.'<br />';
}

【问题讨论】:

  • file_get_html() 不是 php 中的函数。 itr 可能是file_get_contents()
  • @diEcho file_get_html() 来自 simple_html_dom 库。

标签: php curl https html-parsing


【解决方案1】:

改变

$html = file_get_html($query);

到:

$html = str_get_html($query);

file_get_html 函数需要一个文件(或 URL),而不是变量。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-05
    • 2011-01-21
    • 2013-04-06
    • 1970-01-01
    • 2012-01-23
    • 2012-04-22
    • 1970-01-01
    • 2011-03-03
    相关资源
    最近更新 更多