0

我必须在 php 中解析一个页面,该页面的 url 正在进行 302 临时移动标题并移动到一个未找到的页面。它的数据可以通过 mozilla 的 firebug add on 控制台选项手动检索。但是如果我尝试使用 php 解析它,它给了我未找到的页面作为回报。我该如何解析该页面,请建议?

编辑:我正在做这样的事情来获取页面的内容

$file_results = @fopen("http://www.the url to be parses","rb");
    $parsed_results='';
    if($file_results)
    {
        while ($data3 = fread($file_results,"125000"))
        $parsed_results .= $data3;
    }
4

2 回答 2

1

您可以在重定向时使用get_headers()查找所有标题。

$url = 'http://google.com';
$headers = get_headers($url, 1);

print 'First step gave: ' . $headers[0] . '<br />';

// uncomment below to see the different redirection URLs
// print_r($headers['Location']);

// $headers['Location'] will contain either the redirect URL, or an array
// of redirection URLs
$first_redirect_url = isset($headers['Location'][0]) ?
    $headers['Location'][0] : $headers['Location'];

print "First redirection is to: {$first_redirect_url}<br />";

// assuming you have fopen wrappers enabled...
print file_get_contents($first_redirect_url);

继续寻找直到你得到你想要的资源?

于 2010-01-21T06:35:06.183 回答
0

您需要阅读标头,查看它重定向您的位置,并发出另一个请求以获取实际资源。有点痛苦,但这就是协议的工作方式。大多数浏览器透明地执行此操作。

于 2010-01-21T05:47:28.153 回答