【问题标题】:php file_get_contents strange charactersphp file_get_contents 奇怪的字符
【发布时间】:2014-07-02 11:11:30
【问题描述】:

通常我会使用 fil_get_contents 来获取某个页面的 html 结构 但是对于一个特定的站点,我已经尝试了所有我得到的而不是 html 结构 像这样的字符:

J��t��`$ؐ@������iG#)�*��eVe]f@�흼

有人知道它可能是什么吗?我想知道这个网站 有一个保护系统,可以检测请求是否由 一个真实的用户或一个 php 脚本,在第二种情况下它会显示这个。

我使用 curl 来获取页面和指定的浏览器代理,但我猜 我应该通过使用 curl cookie 或更多来更进一步......

我使用的函数(卷曲版):

function getPage($url) {

    $proxies = array();
    $proxies[] = 'proxies here';


    if (isset($proxies)) {
        $proxy = $proxies[array_rand($proxies)];
    }


    $ch = curl_init();

    $header = array(
        'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12',
        'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
        'Accept-Language: en-us,en;q=0.5',
        'Accept-Encoding: gzip,deflate',
        'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7',
        'Keep-Alive: 115',
        'Connection: keep-alive');

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
    curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    $result = curl_exec($ch);

    return $result;
    curl_close($ch);
}

任何帮助将不胜感激。

【问题讨论】:

  • 你能告诉我们你用来获取内容的代码吗?
  • 可能该网站有其他字符集
  • 了解您所谈论的特定网站会很有帮助。
  • 在我的浏览器中可以正常查看。 *页面来源

标签: html file-get-contents invalid-characters


【解决方案1】:

您正在处理字符编码,iconv 函数可能会对您有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-09-05
    • 1970-01-01
    • 1970-01-01
    • 2014-11-04
    • 1970-01-01
    • 2018-10-29
    • 2013-10-29
    • 1970-01-01
    相关资源
    最近更新 更多