标签: file-get-contents

来自url的file_get_contents只有在登录网站后才能访问

我想制作一个可以从网站捕获页面的PHP脚本.想想file_get_contents($ url).

但是,本网站要求您在访问任何页面之前填写用户名/密码登录表单.我想,一旦登录,网站会向您的浏览器发送一个身份验证cookie,并且随后的每个浏览器请求都会将会话信息传递回网站以验证访问权限.

我想知道我如何使用PHP脚本模拟浏览器的这种行为,以获得访问权限并从该网站捕获页面.

更具体地说,我的问题是:

  1. 如何发送包含我的登录详细信息的请求,以便网站回复会话信息/ cookie
  2. 我如何阅读会话信息/ cookie
  3. 如何将此会话信息与每个后续请求(file_get_contents,curl)传回网站.

谢谢.

php authentication session curl file-get-contents

10
推荐指数
1
解决办法
2万
查看次数

如何使用file_get_contents或file_get_html?

我在这里已经阅读了很多问题,我不确定我是否应该使用file_get_contentsfile_get_html为此.

我正在尝试做的就是使用PHP在我的网站上显示这个页面中的两个表:http: //www.statmyweb.com/recently-analyzed/

我知道如何获取他们的整个页面并将其显示在我的网站上当然,但我无法弄清楚如何在不获取页眉/页脚的情况下拉出这两个表格.

php file-get-contents simple-html-dom

10
推荐指数
2
解决办法
6万
查看次数

file_get_contents未找到存在的文件

我有一个文件,我想要另一个脚本来访问使用 file_get_contents

我希望它访问的文件位于它上面的目录中,所以我正在使用 file_get_contents('../file.php?this=that')

然而,它正在回归No such file or directory,我无法理解为什么.文件在那里.

我假设它与本地文件而不是遥控器有关.任何想法或解决方法?

php file-get-contents

9
推荐指数
2
解决办法
4万
查看次数

PHP file_get_contents不适用于localhost

我正在我的网站上从localhost(http://172.16.65.1/)在OSX上运行MAMP服务器.
我想从谷歌加载一些JSON,一些简单的测试告诉我这里有一个问题..

echo file_get_contents("http://www.google.com"); // FAILS
// PHP log: [07-Dec-2011 23:09:21] PHP Warning:  file_get_contents(http://www.google.com) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: Host is down in /Applications/MAMP/htdocs/-tests/get-json.php on line 3
echo file_get_contents("http://www.yahoo.com"); // FAILS

// echo file_get_contents("http://localhost"); // WORKS
// echo file_get_contents("http://172.16.65.1/"); // WORKS - My MAMP server
Run Code Online (Sandbox Code Playgroud)

我该怎么办?它在我的主机提供商服务器上工作正常.

php localhost echo file-get-contents

9
推荐指数
3
解决办法
5万
查看次数

简单的html dom file_get_html无法正常工作 - 是否有任何解决方法?

<?php
// Report all PHP errors (see changelog)
error_reporting(E_ALL);

include('inc/simple_html_dom.php');

    //base url
    $base = 'https://play.google.com/store/apps';

    //home page HTML
    $html_base = file_get_html( $base );

    //get all category links
    foreach($html_base->find('a') as $element) {
        echo "<pre>";
        print_r( $element->href );
        echo "</pre>";
    }

    $html_base->clear(); 
    unset($html_base);

?>
Run Code Online (Sandbox Code Playgroud)

我有上面的代码,我试图获取Play商店页面的某些元素,但它没有返回任何内容.是否有可能在服务器上禁用某些PHP功能来阻止它?

上面的代码在其他网站上完美运行.

有没有解决方法?

php file-get-contents html-parsing simple-html-dom

9
推荐指数
1
解决办法
4万
查看次数

file_get_contents没有返回整个网页

我一直在尝试使用检索网页(http://3sk.tv)的内容file_get_contents.不幸的是,结果输出缺少许多元素(图像,格式化,样式等等),而且基本上看起来与我试图检索的原始页面完全不同.

以前从未尝试过我尝试使用相同方法检索的任何其他URL,但由于某种原因,此特定URL(http://3sk.tv)拒绝正常工作.

我正在使用的代码是:

<?php
$homepage = file_get_contents('http://3sk.tv');
echo $homepage;
?>
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?关于如何正常工作的所有建议将不胜感激.谢谢大家的时间和考虑.

php file-get-contents

9
推荐指数
2
解决办法
1452
查看次数

错误 file_get_contents():读取 8192 字节失败,errno=21

我有一个简单的脚本,它在每个子文件夹的每个文件中搜索给定的字符串。它工作得很好,直到我相信我的 PHP 已更新(我不太确定是否是因为这个)。这是代码:

<?php 
$limit = ini_get('memory_limit');
ini_set('memory_limit', -1);
ini_set('max_execution_time', 300);

function get_directory_content($directory){
    global $search, $results; 

    $files = scandir($directory);

    foreach ($files as $file) {
        if ($file == "." || $file == "..") {
            continue;
        }

        $is_file = false;
        $path = realpath($directory . DIRECTORY_SEPARATOR . $file);

        if (is_dir($path)) {
            get_directory_content($path);
            $is_file = true;
        }
        else{
            $is_file = true;
        }

        if ($is_file) {
            $content = file_get_contents($path);
        }


        if (stripos($content, $search) !== false) {
            $obj = new stdClass();
            $obj->dir = ($directory . DIRECTORY_SEPARATOR …
Run Code Online (Sandbox Code Playgroud)

php errno file-get-contents

9
推荐指数
1
解决办法
4万
查看次数

php:file_get_contents编码问题

我的任务很简单:向translate.google.com发帖请求并获取翻译.在下面的例子中,我使用"hello"这个词翻译成俄语.

header('Content-Type: text/plain; charset=utf-8');  // optional
error_reporting(E_ALL | E_STRICT);

$context = stream_context_create(array(
    'http' => array(
        'method' => 'POST',
        'header' => implode("\r\n", array(
            'Content-type: application/x-www-form-urlencoded',
            'Accept-Language: en-us,en;q=0.5', // optional
            'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7' // optional
        )),
        'content' => http_build_query(array(
            'prev'  =>  '_t',
            'hl'    =>  'en',
            'ie'    =>  'UTF-8',
            'text'  =>  'hello',
            'sl'    =>  'en',
            'tl'    =>  'ru'
        ))
    )
));

$page = file_get_contents('http://translate.google.com/translate_t', false, $context);

require '../simplehtmldom/simple_html_dom.php';
$dom = str_get_html($page);
$translation = $dom->find('#result_box', 0)->plaintext;
echo $translation;
Run Code Online (Sandbox Code Playgroud)

标记为可选的行是那些没有输出相同的行.但我得到了奇怪的人物......

??????
Run Code Online (Sandbox Code Playgroud)

我试过了

echo mb_convert_encoding($translation, 'UTF-8');
Run Code Online (Sandbox Code Playgroud)

但我明白了 …

php encoding file-get-contents

8
推荐指数
2
解决办法
4万
查看次数

读取并解析非常大的文件的内容

我试图解析一个大小约1GB的制表符分隔文件.

在哪里运行脚本我得到:

Fatal error: Allowed memory size of 1895825408 bytes exhausted  (tried to allocate 1029206974 bytes) ...
Run Code Online (Sandbox Code Playgroud)

我的剧本目前只是:

$file = file_get_contents('allCountries.txt') ;

$file = str_replace(array("\r\n", "\t"), array("[NEW*LINE]", "[tAbul*Ator]"), $file) ;
Run Code Online (Sandbox Code Playgroud)

我已经将php.ini中的内存限制设置为-1,然后给了我:

Fatal error: Out of memory (allocated 1029963776) (tried to allocate 1029206974 bytes)
Run Code Online (Sandbox Code Playgroud)

是否有部分打开文件,然后继续下一部分,以便一次使用更少的内存?

php file file-get-contents

8
推荐指数
1
解决办法
3万
查看次数

WebTestCase Phpunit发送原始数据不起作用

我尝试在PhpUnit中的WebTestCase中发送原始数据,但它不起作用:

$jsonEvent = '{
      "type": "invoice.payment_succeeded",
}';
$this->client->request(
    'POST',
    '/api/v1/stripe/webhook',
    [],
    [],
    ['CONTENT_TYPE' => 'application/json'],
    $jsonEvent
);
Run Code Online (Sandbox Code Playgroud)

我尝试获取这样的数据:

$input = file_get_contents("php://input");
var_dump($input);
Run Code Online (Sandbox Code Playgroud)

但是$input空的

不确定但是也许不可能在webtestcase中获得类似的内容输入?

提前致谢.

phpunit file-get-contents raw-data

8
推荐指数
1
解决办法
377
查看次数