php网页采集 修正版

撸羊毛资讯自动采集站的全面解析与实践应用 WordPress的主要功能包括文章和页面的发布、主题和插件的管理、用户权限的分配等。您可以添加新的文章或页面来构建网站内容,并通过添加不同的插件来扩展功能,比如增加搜索引擎优化(SEO)、表单构建、数据分析等。了解这些基本功能对于初学者来说是十分必要的,因为它们构成了WordPress应用的基础。市场上有一些流行的响应式设计框架,如Bootstrap、Foundation和MaterializeCSS,它们为开发者提供了一套预先设计的组件和工具,能够加快响应式网站的开发速度。 阅读详情

修正了在第一组,没有上一组的问题。实现了单次配置,自动化采集,不需人为监控,会自动分类的把HTML网页采集到对应的分类目录,对HTML网页进行过滤和提取就比较简单了

<?php
header("content-type: text/html; charset=utf-8");
class HttpWrap
{
    public $timeout=10;
    public $status='';

    public $host;
    public $port=80;
    private $conn;
    private $path;
    private $url;
    private $scheme;

    public $http_method='GET';
    public $http_version="HTTP/1.1";
    public $agent="Mozilla/5.0 (Windows NT 6.1; rv:33.0) Gecko/20100101 Firefox/33.0";
    public $accept="image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*";
    public $gzip="gzip";
    public $referer;
    public $cookie;
    public $submit_type="application/x-www-form-urlencoded";
    private $accept_language="zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3";
    public $connection="keep-alive";


    private $cmd_line;
    private $header;
    public $post_content;

    private $redirect;
    private $is_gzip;

    public $response_num;
    public $response_header;
    public $response_body_length=0;
    public $response_body;

    public $roll_link;
    public $filename;

   public  function init($url)
    {
        $this->url=$url;
        $url_pair = parse_url($url);
        $this->host = $url_pair['host'];
        $this->path = $url_pair['path'];
        $this->scheme = $url_pair['scheme'];

        if(!empty($url_pair['port']))
        {
            $this->port = $url_pair['port'];
        }
        $this->connect();
       // echo $this->status; exit();
        $this->sendRequest();
        //如果响应头部存在重定向,则对重定向发送请求
        if($this->redirect)
        {
            if(preg_match("#^http://".preg_quote($this->host)."#i",$this->redirect))
            {
                $this->referer=$this->host."/".parse_url($this->redirect)['path'];
                $this->init($this->redirect);
            }
        }
        if($this->roll_link)
        {
            $next_url = substr($this->url,0,strripos($this->url, '/')+1).$this->roll_link;
            //当进入最后一页时,跳转到下一组
            if(strtolower(trim(basename($this->url,'.html'))) == strtolower(trim(basename($next_url,'.html'))))
            {
                //对下一组网页进行采集
                echo str_repeat("  ", 2048);
                echo "<font color='red'>对下一组网页进行采集</font><br />";
                $next_group = $this->getNextGroup($this->filename);
                sleep(1);
                $this->init($next_group);
                //echo $next_group;

            }
            else
            {
                $this->init($next_url);
            }

        }

    }

   private function connect()
   {
       $this->conn = fsockopen($this->host,$this->port,$errno,$errstr,$this->timeout);
       if($this->conn)
       {
           $this->status = '链接成功';
           return true;
       }
       else
       {
            switch($errno)
            {
                case -3:
                        $this->status="创建socket链接失败";
                case -4:
                        $this->status="dns查询失败";
                case -5:
                        $this->status="链接被拒绝或超时";
                default:
                        $this->status="创建连接失败";
            }
            return false;
       }
   }
   private function sendRequest()
   {
       if(empty($this->path))
       {
           $this->path="/";
       }
       $this->cmd_line=$this->http_method." ".$this->path." ".$this->http_version."\r\n";

       if(!empty($this->host))
       {
           $this->header .= "Host: ".$this->host."\r\n";
       }

       if(!empty($this->agent))
       {
           $this->header .="User-Agent: ".$this->agent."\r\n";
       }

       if(!empty($this->accept))
       {
           $this->header .= "Accept: ". $this->accept ."\r\n";
       }
       if(!empty($this->gzip))
       {
           if ( function_exists("gzinflate") )
           {
                $this->header .= "Accept-encoding: gzip\r\n";
            }
            else
            {
                $this->status = "不支持压缩";
            }
       }
       if(!empty($this->referer))
       {
           $this->header .= "Referer: ".$this->referer."\r\n";
       }
       if(!empty($this->accept_language))
       {
           $this->header .= "Accept-Language: ".$this->accept_language."\r\n";
       }
       if(!empty($this->cookie))
       {
           if(!is_array($this->cookie))
           {
               $this->header .="Cookie: ".$this->cookie;
           }
           else
           {
               if(count($this->cookie) >0)
               {
                   $cookie = "Cookie: ";
                   foreach($this->cookie as $key => $val)
                   {
                       $cookie.=$key."=".urlencode($val).";";
                   }
                  $cookie = substr($cookie, 0, strlen($cookie)-1)."\r\n";
               }
               $this->header .= $cookie;
           }
       }
       if(!empty($this->submit_type))
       {
           $this->header .="Content-Type: ".$this->submit_type."\r\n";
       }
       if(!empty($this->post_content))
       {
           $this->header .= "Content-length: ".strlen($this->post_content)."\r\n";
       }
       if(!empty($this->connection))
       {
           $this->header .= "Connection: ".$this->connection."\r\n";
       }
       $this->header .="\r\n";
       //上面是HTTP请求头部信息
       //echo $this->cmd_line.$this->header.$this->post_content; exit();
       //发送请求
       $len = strlen($this->cmd_line.$this->header.$this->post_content);
      if($len != fwrite($this->conn, $this->cmd_line.$this->header.$this->post_content,$len))
      {
          $this->status = "发送请求failed";
      }

       //接受响应,每次读取一行内容,首先解析响应头
       while($response_header = fgets($this->conn, 1024))
       {
           if(preg_match("|^HTTP/|",$response_header))
            {
                //匹配状态数字,200表示请求成功
                if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$response_header, $status))
                {
                        $this->response_num= $status[1];//返回代表数字的状态
                }
            }
            //echo $this->response_num; exit();
            // 判断是否需要重定向
            if(preg_match("#^(Location:|URI:)#i",$response_header))
            {
                // 获取重定向地址
                preg_match("#^(Location:|URI:)\s+(.*)#",trim($response_header),$matches);

                //如果重定向字段不包含主机名,不是以以://开头的,则拼接王完整的请求地址,模式+主机+端口
                if(!preg_match("#\:\/\/#",$matches[2]))
                {
                    // 补全主机名
                    $this->redirect = "http://".$this->host.":".$this->port;

                    //添加路径
                    if(!preg_match("|^/|",$matches[2]))
                           $this->redirect .= "/".$matches[2];
                    else
                           $this->redirect .= $matches[2];
                }
                else
                //包含完整的主机地址
                        $this->redirect = $matches[2];
            }

        //判断返回的数据的压缩格式
	if (preg_match("#^Content-Encoding: gzip#", $response_header) )
          {
                $this->is_gzip = true;
          }
          if(preg_match('#^Content-Length:\s*(\d+)#i', $response_header, $len))
          {
              $this->response_body_length = $len[1];
          }

        //解析完响应头部
        if(preg_match("/^\r?\n$/", $response_header) )
            break;

        $this->response_header[]=$response_header;
       }
       //可以成功返回响应头部信息,响应状态码也为200
      // var_dump($this->response_header); exit();

        if($this->response_num==200)
        {
            //问题出在这里
            //echo "ok"; exit();
            $sub_dir;
            $dirname;
            $path;
            $filename;
            if(preg_match('#/(\d+)/#', $this->url, $sub_dir))
            {
                $dirname = "./download/".$sub_dir[1];
            }
            else
            {
                $dirname = "./download/".date("Ymd");
            }

            $len=0;
            while($items = fread($this->conn, $this->response_body_length))
            {
                if(!is_dir($dirname))
                {
                    $path = mkdir($dirname,0777,true);
                }
                $filename = $dirname.'/'.basename($this->url,'.html').'.txt';
                //保存的总是最后一个文件,也就是采集完一组网页后的最后一页
                $this->filename = $filename;
                $len = $len+strlen($items);
                file_put_contents($filename, $items, FILE_APPEND);
                //这里必须判断读取的长度,不然会在这里阻塞
                if($len >= $this->response_body_length) break;

            }

            if($this->is_gzip)
            {
                $this->response_body = gzinflate ($this->response_body);
            }
            echo str_repeat("  ", 2048);
            echo "对链接".$this->url."发起请求<br />";
            sleep(1);
            $this->getRollLink($filename);
           // sleep(1);
        }
   }
    private function getRollLink($filename)
   {
       if(!file_exists($filename)) die($filename.'文件不存在__'.__LINE__);
       $temp=file_get_contents($filename, false, null, 0, 64);
        $encoding=mb_detect_encoding($temp, array('GB2312','GBK','UTF-8','BIG5','LATIN1'));
        $content='';
        if($encoding !='UTF-8')
        {
                $content = mb_convert_encoding(file_get_contents($filename), 'UTF-8', $encoding);
        }

       if(preg_match('#<ul\s+class="image"[^>]*?>.*?</ul>#is', $content, $match))
       {
           if(preg_match('#<a\s+href="([^"]+?)">下一页</a>#ui', $match[0], $next))
           {
                $this->roll_link =  $next[1];
           }
       }
       else
       {
          $this->roll_link = false;
       }
   }
   private  function getNextGroup($filename)
   {
        $temp=file_get_contents($filename, false, null, 0, 64);
        $encoding=mb_detect_encoding($temp, array('GB2312','GBK','UTF-8','BIG5','LATIN1'));
        $content='';
        if($encoding !='UTF-8')
        {
                $content = mb_convert_encoding(file_get_contents($filename), 'UTF-8', $encoding);
        }

	if(preg_match('#<ul\s+class="page"[^>]*?>.*?</ul>#is', $content, $match))
       {
			//echo $match[0]."<br />";
           if(preg_match_all('#<a\s+href="([^"]*?)">.*?</a>#usi', $match[0], $next))
           {
                //var_dump($next[1]);
                $choice;
                if(count($next[1])==2)
                {
                    $first = basename($next[1][0], ".html");
                    $second = basename($next[1][1], ".html");
                    //往前翻页,进入下一组
                    if(intval($first) < intval($second))
                    {
                            $choice = $first;
                    }
                    else
                    {
                            $choice = $second;
                    }
                    //h获取下一组
                    foreach($next[1] as $item)
                    {
                        if(strripos($item, $choice) !=false )
                        {
                            if(substr($item, 0,2) =='..')
                            {
                                    $link=  substr($item, 2);
                                    $sub_path = explode('/', $this->path);
                                    $url = $this->scheme.'://'.$this->host.'/'.$sub_path[1].$link;
                                    return $url;
                            }
                        }
                    }
                }
                //如果是最后一组,即没有下一组了
                else if(count($next[1])==1)
                {
                      if(substr($next[1][0],0,2)=='..')
					  {
							$link = substr($next[1][0],2);
							$sub_path = explode('/', $this->path);
                            $url = $this->scheme.'://'.$this->host.'/'.$sub_path[1].$link;
                            return $url;
					  }
                }
           }
           else
           {
               $this->status = "failed to match href";
           }

       }
       else
       {
            $this->status = "failed to match class=page";
       }
   }

}
ob_implicit_flush(true);
set_time_limit(0);
$url = $url = "http://www.mmkao.com/Beautyleg/201412/7044.html";
$http = new HttpWrap();
$http->cookie = "safedog-flow-item=41E2DBFEF121A8A2835ADB4476E5D3EC";
$http->referer = "www.mmkao.com";
$http->init($url);
?>


Springboot——接入企业微信聊天机器人 最近企业微信的聊天机器人很火也很好玩,本期想自己接入一个玩玩试试水,同时也接入AI大模型进行数据的交互。 阅读详情

相关推荐

高效获取Sentinel-2影像:哥白尼数据中心下载全流程解析

本文提供了一份从哥白尼数据中心高效下载Sentinel-2卫星影像的保姆级指南。详细解析了从账号注册、使用Copernicus Browser界面、精准划定研究区域,到利用云量覆盖、时间范围等关键条件筛选L2A地表反射率产品的全流程,旨在帮助用户快速获取高质量遥感数据,避免常见错误。

weixin_29247219的博客 256

php分页采集数据,php实现分页调取数据库记录

学生信息管理function doDel(id){if(confirm("确认要删除吗?")){window.location="action.php?action=del&id="+id;}}img {border:0;}.tiao{width:30px;}session_start();////////////////////////这里用来判断输入的跳转页数是否能超范围 由于这些语句...

weixin_39959569的博客 276

基于STM32的半导体制冷片温度控制

制冷片温度控制,温控范围15℃~45℃,本人菜鸡一枚,大佬绕路。 #include "stm32f10x_gpio.h" #include "relay.h" void relay_Init(void){ GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);//Ê...

大白兔的博客 9015

php采集分页数据,如何通过php+wordpress实现分页获取数据

1.首先我们通过WordPress来搭建我们的博客网站,需要实现分页获取数据,我们需要了解一下WordPress给我们提供的api。主要是get_posts()这个api的使用方法。函数的结构大概长这么个样子: ,其中$args是需要传入的参数。那么这个参数都有什么呢?下面就贴个图吧。get_posts()函数的参数有关get_posts函数的更多介绍:http://www.boke8.net/...

weixin_39951295的博客 354

Cadence17.4 Allegro PCB制板(gerber / 光绘)文件输出的顺序及注意点

Cadence Allegro PCB制板文件输出 (gerber 光绘文件输出)

weixin_45331044的博客 1万+

基于航天宏图PIE-SAR软件的高分三号(GF-3)SAR影像的预处理

软件官网 航天宏图—国内领先的卫星运营与应用服务提供商(官网) 一、数据导入 数据导入-GF-3-根据模式选择 参数文件导入解压后GF-3数据的XML文件 通道自动填充 设置输出目录 确定 等待,加载图像、自动构建金字塔 二、复数数据转换 强度/幅度特征是SAR影像最主要的特征之一,基于SAR强度/幅度影像可以提取地物目标信息,因此需要将SAR复数数据转换为SAR强度/幅度数据。导入输入影像,设置参数类型,输出目录、命名、类型; 漫长的等待 三、多视 为提...

weixin_52127098的博客 9003

php mysql 高效分页_php 高效分页

mysql.php 获取数据库中的记录,完全个人经验总结,仅供参考!/***PHP+MYSQL数据库基本功能*http://blog.youkuaiyun.com/yown*/#############################################获取序列ID############################################function getSequence() ...

weixin_29735807的博客 343

避坑指南:Ubuntu 22.04上源码编译Autoware.universe(Humble版)的完整流程与常见错误修复

本文详细介绍了在Ubuntu 22.04上源码编译Autoware.universe(Humble版)的完整流程与常见错误修复方法。从环境准备、依赖安装到编译优化,提供了实用的避坑指南和解决方案,帮助开发者高效完成安装并避免常见问题。特别针对源码安装过程中的疑难杂症给出了具体修复建议。

weixin_33712987的博客 382

php中实现网页的链接,PHP取网页所有链接实现程序代码总结

本文章来给大家介绍在PHP取网页所有链接实现程序代码,有直接利用正则的也有用在采集中过滤所有连接地址,有需要了解的朋友可参考。我们核心代码就是正则表达试了 代码如下 复制代码 function get_all_url($code){preg_match_all(‘/"' ] )["|']?s*[^>]*>([^>] )/i’,$code,$ar...

weixin_31599065的博客 723

配电网故障重构/孤岛划分/故障恢复

程序主要复现《基于GA_BFGS算法的配电网故障恢复性重构研究_郑海广》,采用matlab编程软件实现,依据网络结构和DG供电方式对配电网进行孤岛划分,将含有 DG 的配电网拓扑结构看成一个树,搭建成连通图模型,使得将孤岛的划分变成了求取最小生成树,以网损和开关开断次数作为目标,采用 IEEE33 节点配电网为算例,通过遗传算法寻优计算,从而得到最佳的重构方案。

zhangxd212489的博客 2500

【RBF预测】基于粒子群算法优化RBF神经网络实现数据回归预测含Matlab源码

1 简介 原油含水率预测对于确定油井水,油层位以及估计原油产量有着非常重要意义.BP神经网络是最近常用的原油含水率预测方法,然而,由于BP神经网络存在容易陷入局部极小值,收敛速度慢等问题,影响了其预测的实用性和准确性,对此,提出基于粒子群优化RBF神经网络(PSO-RBFNN)的原油含水率预测方法,粒子群优化算法用于RBF神经网络参数优化.在分析原油含水率预测的影响因素基础上,建立粒子群优化RBF神经网络的原油含水率预测模型.实验结果表明,在原油含水率预测中,基于粒子群优化RBF神经网络比BP神经网络有着

qq_59747472的博客 1234

html过滤 -java_PHP过滤各种html标签

1.strip_tags(剥去字符串中的 HTML 标签)strip_tags() 函数剥去字符串中的 HTML、XML 以及 PHP 的标签。2.字符串替换str_replace(array("","&nbsp;","\t","\r\n","\r","\n"),array("","","","","","")3.利用正则表达式(效率稍微低一些)$str=preg_replace("/\...

weixin_39561431的博客 300

openbmc mctp i3c适配步骤

本文介绍了在Intel OKS平台下,BMC作为I3C从设备如何适配MCTP over I3C的实现方法。主要内容包括:1)关键术语解释,如MDB(Mandatory Data Byte)值为0xAE,DCR(Device Characteristics Register)和BCR(Bus Characteristics Register)的设置;2)适配流程说明,包括BMC作为控制器主节点分配地址后成为MCTP端点,CPU作为总线所有者的角色转换;3)测试验证步骤,展示通过mctp-client工具发送指

wit_yuan的专栏 132

分享158个ASP源码,总有一款适合您

asp

zdh13370188237的博客 592

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

分享137个ASP源码,总有一款适合您

ASP

zy0412326的专栏 1036

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

分享80个ASP整站程序源码,总有一款适合您

分享80个ASP整站程序源码,总有一款适合您

zy0412326的专栏 397

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

分享156个ASP源码,总有一款适合您

ASP

MankTang的博客 273

最新为什么要学习Python,0基础学习Python难吗?(1),网络安全入门视频教程

当我学到一定基础,有自己的理解能力的时候,会去阅读一些前辈整理的书籍或者手写的笔记资料,这些笔记详细记载了他们对一些技术点的理解,这些理解是比较独到,可以学到不一样的思路。Python所有方向的技术点做的整理,形成各个领域的知识点汇总,它的用处就在于,你可以按照上面的知识点去找对应的学习资源,保证自己学得较为全面。观看零基础学习视频,看视频学习是最快捷也是最有效果的方式,跟着视频中老师的思路,从基础到深入,还是很容易入门的。**科学计算:**在科学计算也应用越来越广泛,常用的模块有Numpy、SciPy。

2401_84302628的博客 790

为什么要学习Python,0基础学习Python难吗?,2024年最新网络安全面试精讲

当我学到一定基础,有自己的理解能力的时候,会去阅读一些前辈整理的书籍或者手写的笔记资料,这些笔记详细记载了他们对一些技术点的理解,这些理解是比较独到,可以学到不一样的思路。Python所有方向的技术点做的整理,形成各个领域的知识点汇总,它的用处就在于,你可以按照上面的知识点去找对应的学习资源,保证自己学得较为全面。观看零基础学习视频,看视频学习是最快捷也是最有效果的方式,跟着视频中老师的思路,从基础到深入,还是很容易入门的。**科学计算:**在科学计算也应用越来越广泛,常用的模块有Numpy、SciPy。

2401_83947398的博客 736

最新为什么要学习Python,0基础学习Python难吗?,2024年最新网络安全入门基础

在结束之际,我想重申的是,学习并非如攀登险峻高峰,而是如滴水穿石般的持久累积。尤其当我们步入工作岗位之后,持之以恒的学习变得愈发不易,如同在茫茫大海中独自划舟,稍有松懈便可能被巨浪吞噬。然而,对于我们程序员而言,学习是生存之本,是我们在激烈市场竞争中立于不败之地的关键。一旦停止学习,我们便如同逆水行舟,不进则退,终将被时代的洪流所淘汰。因此,不断汲取新知识,不仅是对自己的提升,更是对自己的一份珍贵投资。让我们不断磨砺自己,与时代共同进步,书写属于我们的辉煌篇章。需要完整版PDF学习资源私我。

2401_84302628的博客 671

为什么要学习Python,0基础学习Python难吗?

为什么要学习Python,0基础学习Python难吗?

喜欢Python编程的程序员柚柚呀 71

分享151个ASP源码,总有一款适合您

asp源码

zy0412326的专栏 979

2024年最全为什么要学习Python,0基础学习Python难吗?(1),2024年最新网络安全中高级岗面试为何越来越难

本人从事网路安全工作12年,曾在2个大厂工作过,安全服务、售后服务、售前、攻防比赛、安全讲师、销售经理等职位都做过,对这个行业了解比较全面。最近遍览了各种网络安全类的文章,内容参差不齐,其中不伐有大佬倾力教学,也有各种不良机构浑水摸鱼,在收到几条私信,发现大家对一套完整的系统的网络安全从学习路线到学习资料,甚至是工具有着不小的需求。最后,我将这部分内容融会贯通成了一套282G的网络安全资料包,所有类目条理清晰,知识点层层递进,需要的小伙伴可以点击下方小卡片领取哦!

2401_84301922的博客 832

今天去徐汇区吃了鱼火锅!

[新] Invision Gallery v2.0.3 简体中文语言包 .exe 260.00 KB [新] BlogEz v1.2 .exe 260.00 KB [新] SugarCRM v3.5.0c 简体中文版(权限版) .exe 260.00 KB [新] UPU(UGiA PHP ...

iteye_19422的博客 291

php获取网页内容过滤,php获取网页内容方法

用php抓取页面的内容在实际的开发当中是非常有用的,如作一个简单的内容采集器,提取网页中的部分内容等等抓取到的内容在通过正则表达式做一下过滤就得到了你想要的内容,至于如何用正则表达式过滤,在这里就不做介绍了,有兴趣的,以下就是几种常用的用php抓取网页中的内容的方法。...

weixin_39837041的博客 327

dede文章采集管理php,dedecms采集过滤

dede采集过程中最麻烦的莫过于采集的正则过滤函数的编写。说实在的,dede在这点上和很多ASP CMS系统比如说动易等,采集的时候直接选择几个选项就可以了,简单的完成想过滤的东西。不过他们只局限于对文章内容的过滤不是很好。而DEDE却能对所有采集的字段进行过滤,功能上弥补了易用性的缺陷,期待柏拉图在后续版本中加上选择性过滤功能。下面是在综合论坛上网友的各种正则的一个全集:以下为引用的内容:{de...

weixin_28452161的博客 179
上一篇: 附加功能---显示词库的分类信息
下一篇: php网页采集 想对高效版
错_对
博客等级 码龄16年 68粉丝 80原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值