【问题标题】:php timeout with file_get_htmlphp超时与file_get_html
【发布时间】:2015-01-30 08:47:51
【问题描述】:

我一直在尝试使用 simple_html_dom lib for php 从 wikia 网站获取一些数据。基本上我所做的是使用 wikia api 转换为 html 渲染并从那里提取数据。提取后,我会将这些数据泵入mysql数据库进行保存。我的问题是,通常我会提取 300 条记录,并且我会停留在 93 条记录上,其中 file_get_html 为空,这将导致我的 find() 函数失败。我不确定为什么它会停止在 93 条记录,但我尝试了各种解决方案,例如

   ini_set( 'default_socket_timeout', 120 );
   set_time_limit( 120 );

基本上我必须访问 wikia 页面 300 次才能获得这 300 条记录。但大多数情况下,我会设法在 file_get_html 为空之前获得 93 条记录。知道如何解决这个问题吗?

我也有测试 curl 并且有同样的问题。

function test($url){
 $ch=curl_init();
 $timeout=5;

 curl_setopt($ch, CURLOPT_URL, $url);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

 $result=curl_exec($ch);
 curl_close($ch);
 return $result;
 }

 $baseurl = 'http://xxxx.wikia.com/index.php?';

 foreach($resultset_wiki as $name){
  // Create DOM from URL or file
 $options = array("action"=>"render","title"=>$name['name']);
 $baseurl .= http_build_query($options,'','&');
 $html = file_get_html($baseurl);
 if($html === FALSE) {
 echo "issue here";
 }
  // this code for cURL but commented for testing with file_get_html instead
  $a = test($baseurl);
  $html = new simple_html_dom();
  $html->load($a);

    // find div stuff here and mysql data pumping here.
 }

$resultsetwiki 是一个数组,其中包含要从 wikia 获取的标题列表,基本上,resultsetwiki 数据集也是在执行搜索之前从 db 加载的。

实际上我会遇到这种类型的错误

  Call to a member function find() on a non-object in 

【问题讨论】:

  • 您是否尝试全部使用curl
  • 是的,我做到了,但我仍然会得到相同的结果,即在记录 93 上遇到空问题。就像不使用 curl 一样。
  • 网站不只是限制你,因为你在很短的时间内向他们发送了大量的电话吗?
  • 无论如何要解决这个问题?

标签: php simple-html-dom


【解决方案1】:

回答了我自己的问题,似乎是我正在使用的 URL,我已更改为 curl 与 post 来发布操作和标题参数

【讨论】:

    猜你喜欢
    • 2015-06-21
    • 1970-01-01
    • 1970-01-01
    • 2014-06-05
    • 2016-05-23
    • 1970-01-01
    • 2013-06-07
    • 2013-04-29
    • 2012-12-01
    相关资源
    最近更新 更多