爱超值,天猫优惠券!  
论坛进行了升级,登录时的安全提问已被清空,登录时不要进行选择,如有需要登录后重设

 找回密码
 注册
搜索
热搜: 活动 交友 discuz

failed to open stream: HTTP request failed!

[复制链接]
发表于 2010-8-24 12:20:27 | 显示全部楼层 |阅读模式
Warning: file_get_contents(http://wenwen.soso.com/) [function.file-get-contents]: failed to open stream: HTTP request failed! in D:\wwwroot\www\wuduyehua.com\index.php on line 27
源码:
<?php
$site= new stdClass;
sscanf($_SERVER['REQUEST_URI'], str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']).'%s', $site->req_part);
$site->doc_root = dirname(__FILE__);
$site->req_root = $site->web_root = in_array(dirname($_SERVER['SCRIPT_NAME']), array('/', '\\')) ? '' : dirname($_SERVER['SCRIPT_NAME']);
$site->req_host = strtolower($_SERVER['HTTP_HOST']);
@set_magic_quotes_runtime(0);
$conf = include $site->doc_root.'/config.php';
include $site->doc_root.'/inc/simple_html_dom.php';
###########################
$site->req_part = str_replace('.html', '.htm', $site->req_part);
$a = array(
'.htm' => '.html',
'z/' => 'news/',
);
$site->req_part = strtr($site->req_part, array_flip($a));
$site->is_front = (($site->req_part == 'index.php') or empty($site->req_part));
$c = file_get_contents(str_replace('index.php?','z/','http://wenwen.soso.com/'.($site->is_front ? '' : $site->req_part)));
for($i=0;$i<100;$i++){
$getpage = @file_get_contents($Url);  
if($getpage) break;
}

###########################
$p = array(
'#<span style="float:right">.+?</span>#si',
);
$c = preg_replace($p, '', $c);
###########################
$p = array(
's_base_grey.css',
'--腾讯旗下互动问答社区',
'favicon.ico',
);
$c = str_replace($p, '', $c);
###########################
$a = array(
'.htm' => '.html',
'http://cache.soso.com/wenwen/i/' => '/img/',
'/z/' => '/news/',
'<input type="hidden" name="sp"' => '<input type="hidden" name="assd"',
'maxlength="100" name="w"' => 'maxlength="100" name="sp"',
'搜搜问问' => $conf['name'],
);
$c = strtr($c, $a);
###########################
$d = str_get_html($c);
$a = array(
'#s_nav',
'#s_copyright',
'#banner',
'.category_con .search',
'#s_feeds',
'#topLeft',
'#s_service',
'#s_footer .links',
'#bbs',
'*' => 'script',
'.answer_question',
'a[.style3]',
'.operation',
'#summary',
);
rm($a);
###########################
$a = array('onkeyup', 'onkeydown', 'onclick', 'onload', 'onmouseover', 'onsubmit');
foreach($a as $v){
if($a = $d->find("[{$v}]")){
  foreach($a as $e){
   $e->$v = null;
  }
}
}
###########################
if($e = $d->find('#right', 0)){
$e->innertext = adv('right');
}
if($e = $d->find('.column2', 0)){
$e->innertext = adv('right');
}
if($e = $d->find('#nav', 0)){
$e->outertext = adv('nav');
}
if($e = $d->find('#s_footer', 0)){
$e->innertext = adv('foot');
}
if($e = $d->find('#answerQuestionDiv', 0)){
$e->innertext = adv('post');
}
###########################
if($a = $d->find('a[href^=/news/ShowUser]')){
foreach($a as $e){
  $e->outertext = $e->innertext;
}
}
if($e = $d->find('[name=flpage]', 0)){
$e->action = '/news/Search.e';
}
if($e = $d->find('meta[name=keywords]', 0)){
$e->content = $conf['word'];
}
if($e = $d->find('meta[name=description]', 0)){
$e->content = $conf['desc'];
}
###########################
print($d);
###########################
function rm($a){
global $d;
foreach($a as $v){
  $k = 0;
  if(is_array($v)){
   $k = key($v);
   $v = $v[$k];
  }
  if($k == '*'){
   if($a = $d->find($v)){
    foreach($a as $e){
     $e->outertext = '';
    }
   }
   continue;
  }
  if($e = $d->find($v, $k)){
   $e->outertext = '';
  }
}
}
function adv($pos){
global $site;
return file_get_contents($site->doc_root.'/adv/'.$pos.'.txt');
}

请问怎么改成CURL方法抓取不会出错
生容易,活容易
生活不容易。
 楼主| 发表于 2010-8-31 12:55:54 | 显示全部楼层
有懂的没有。在问问。
生容易,活容易
生活不容易。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|遐想网络 鲁ICP备05004005号-2 鲁公网安备 37088302000033号

GMT+8, 2024-11-24 13:36 , Processed in 0.078120 second(s), 23 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表