php利用file_get_contents函数抓取网页指定内容

file_get_contents获取不到网页内容的解决方法 file_get_contents获取不到网页内容的解决方法,需要的朋友可以参考一下 立即下载

今天在csdn上面看到有人问,抓取页面指定内容,然后预算100以内,然后就点了个竞标,虽然不知道能不能拿下来,毕竟一百也是钱啊偷笑,然后想想看怎么做,代码直接贴上来算了,看到了就赚到了。

<?php

//有些网页加载时间比较长,可以通过动态设置执行最大时间,可选
//ini_set("max_execution_time", "45");

//有些网页有防盗链,可以模拟成浏览器去请求,可选
ini_set('user_agent','Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; 4399Box.560; .NET4.0C; .NET4.0E)');


$url = 'http://news.sohu.com/';


//也可以用fopen或者强大的curl
$info=file_get_contents($url);

//针对编码问题,可以转码,可选
//$info =  mb_convert_encoding($html,'utf8','gbk');

//如果想只匹配一次,可以用preg_match函数
preg_match_all('/<h1><a href="(.*)" title="" .*>(.*)<\/a><\/h1>/i',$info,$m);

//结果已经出来啦
//var_dump($m);

//把找到了链接和新闻,组装成k=>v形式,这样方便展示到自己的页面上
$news = array_combine($m[1],$m[2]);

var_dump($news);

就这样,我们就得到了搜狐新闻的h1标题新闻啦。

结果如下:

PHP中使用file_get_contents post数据代码例子 废话不多说,上代码: 复制代码 代码如下: $data = array(     ‘name’ => ‘Joe’,     ‘website’ => ‘www.jb51.net’ ); $data = http_build_query($data); $data = json_encode($data); $json = file_get_contents($url, 0, stream_context_create(array(     ‘http’ => array(         ‘timeout’ => 30,         ‘method’ => ‘POST’,         立即下载

相关推荐

lumerical中DEVICE和MODE模块的交互使用(真的很干货!!可以自信的说网上绝对找不到比我更详细的步骤了)

几个脚本文件很重要! Lumerical仿真流程: 一、DEVICE: (1).建模并且运行完之后,在脚本提示符下键入以下脚本行以运行plotDopingProfile.lsf如图1(文件名如果索引不到的话就可以把文件直接用notepad++打开,然后把代码直接输入到device中script脚本中 如图2)脚本文件并生成下图 如图3: (图2) (图1) (图3) (2).仿真...

1万+

PHP中用file_get_contents抓取网页

1.用 file_get_contents 访问 http 时取回响应头 file_get_contents('http://www.baidu.com/'); var_dump($http_response_header); 输出如下: array(9) {   [0]=>   string(15) "HTTP/1.1 200 OK"   [1]=>   string(35) "

打杂人-aerchi 5204

别再瞎调参数了!分子动力学模拟新手必看的力场选择与验证实战指南

本文为分子动力学模拟新手提供力场选择与验证的实战指南,详细解析主流力场特性及适用场景,并通过水分子案例演示完整的验证流程。文章重点对比SPC/E、TIP3P和OPLS-AA三种力场在GROMACS中的表现,帮助读者避免常见参数调整误区,提升模拟准确性。

weixin_26934905的博客 425

file_get_contents() 函数抓取网页

有时候用 file_get_contents() 函数抓取网页会发生乱码现象。有两个原因会导致乱码,一个是编码问题,一个是目标页面开了Gzip。 编码问题好办,把抓取到的内容转下编码即可($content=iconv("GBK", "UTF-8//IGNORE", $content);),我们这里讨论的是如何抓取开了Gzip的页面。怎么判断呢?获取的头部当中有Content-Encoding

1301

手把手教你搭建Howland电流源:从原理图到实测避坑指南(附Python数据分析)

本文详细介绍了Howland电流源的设计与实现,从原理图到实测避坑指南,涵盖电阻匹配、运放选择和PCB布局等关键环节。通过Python数据分析,展示了如何优化电路性能并解决常见问题,适合电子工程师和爱好者参考。

weixin_29291069的博客 632

深入瑞芯微SDK:手把手解析Uboot、Kernel到Rootfs的镜像生成与烧录

本文深入解析瑞芯微SDK中从Uboot、Kernel到Rootfs的镜像生成与烧录全流程,揭示编译背后的技术细节。通过详细分析SDK架构、镜像生成流水线、分区表定制、Rootfs构建及烧录科学,帮助开发者从会编译进阶到懂原理,掌握系统级开发的关键技术。

weixin_29193359的博客 270

file_get_contents()对指定网页或API实现get+post请求并传输获取数据

//GET请求方法 $url="https://www.baidu.com"; $ret=file_get_contents($url); $list=json_decode($ret,1);//把json转为数组格式,视个人情况转换//POST和GET通用请求方法 $url="https://www.baidu.com"; $data=['username'=>'*...

武景涛的博客 485

【漏洞复现】永恒之蓝 MS17-010 远程溢出漏洞(CVE-2017-0143)

文章目录声明前言一、漏洞原理简述二、漏洞代码深层解析三、实验步骤四、漏洞补丁总结 声明 本篇文章仅用于技术研究与技术学习,切勿用于非授权下攻击行为,切记! 前言 Windows7 存在 MS17-010 永恒之蓝(远程溢出漏洞) ,该漏洞是方程式组织在其漏洞利用框架中一个针对SMB服务进行攻击的漏洞,该漏洞导致攻击者在目标系统上可以执行任意代码 一、漏洞原理简述 MS17-010漏洞出现在Windows SMB v1中的内核态函数 srv!SrvOs2FeaListToNt 在处理FEA(File Ex

李同學AI安全 9627

PHP获取网页内容的几种方法

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

wakice的博客 1万+

Harmony:C# 动态代码补丁的5大秘密武器

Harmony 是一个开源库,它允许你在运行时修改托管代码(即使用 .NET 或 Mono 编译的语言编写的应用程序)。它通过利用 AOP(面向切面编程)的思想,可以在不重新编译代码的情况下添加、替换或修改方法的行为。这对于游戏模组(Modding)、插件开发以及调试工具非常有用。安装 Harmony要使用 Harmony,你需要首先安装它。Harmony 作为一个 NuGet 包,可以直接通过 Visual Studio 的 NuGet 包管理器进行安装。安装步骤打开 Visual Studio。

java专栏 1191

ardupilot SBUS输入捕获

本节主要记录ardupilot 的sbus 输入捕获功能。ardupilot 默认支持多种无线协议控制输入设备,比如常用的PPM,SBUS,IBUS,DSM,SUMD,SRXL等协议,本节主要讲解ardupilot 如何通过定时器的pwm输入捕获来获取sbus数据。

陌城烟雨 269

php获取网页的内容file get,php 的file_get_contents函数获取网页内容不全的问题。

$a = file_get_contents('http://www.giabbs.com/thread-756955-1-1.html');var_dump($a);file_put_contents('a.txt', $a);代码如上面。运行代码就发现,内容只获取到一半。在中间断掉了。这种情况一般是转码的情况,有些特殊字符无法转换,然后断掉的。可是为啥用这个函数获取原始内容也这样,真心想不通啊...

weixin_30224231的博客 696

2025_NIPS_Better Tokens for Better 3D: Advancing Vision-Language Modeling in 3D Medical Imaging

近年来,3D医学成像领域的视觉语言建模取得了显著进展,这得益于大规模带配对自由文本报告的计算机断层扫描(CT)语料库、更强大的架构以及高性能预训练模型。这些进展推动了自动报告生成和文本条件3D图像合成等应用的发展。然而,现有方法在处理高分辨率、长序列体积数据时仍面临挑战:对比预训练往往导致视觉编码器与临床语言错位,而基于切片的令牌化会模糊精细解剖结构,降低下游任务的诊断性能。

c_cpp_csharp的专栏 90

php 只显示部分内容吗,file_get_contents只读取网页的部分内容

file_get_contents只读取网页的部分内容,其实这就是采集文章最简单最原始的做法了。在php教程中file_get_contents函数可以打开本地文件,也可能读取远程文件用法file_get_contents( $url);下面我们来看一下file_get_contents采集远程网站的内容的实例 代码如下 复制代码 $url = http://w...

weixin_42502736的博客 266

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

FILE_GET_CONTENTS 加数据头

$opts = array(  http=>array(  method=>"GET",  header=>"Host: style.china.alibaba.com/r/n" .    "Accept-language: zh-cn/r/n" .    "User-Agent: mozilla/5.0 (windows; u; windows nt 5.1; zh-cn; rv:1

nsource的专栏 762

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

PHP 获取页面内容和保存页面内容

&lt;meta charset="utf-8"&gt; &lt;?php $url = "http://onestopweb.iteye.com/"; //file_get_contents() 把整个文件读入一个字符串中。 $contents = file_get_contents($url); //对 $contents 进行操作 //file_put_cont...

一直专注于互联网 1652

深度学习工具包 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")

采集(file_get_contents)

//用file_get_contents进行采集 header("content-type:text/html;charset=utf-8"); $url="http://www.php7.com/dwzchd/aa.html"; $file=file_get_contents($url); $pre='#(.*)#isU'; preg_match($pre,$file,$conte

郝云博客 4269

php中调用其他系统http接口的方法

使用函数:  file_get_contents($url); 传入接口url及其参数:如 $url="http://192.168.1.1/test.jsp?id=1&type=2";$ret=file_get_contents($url);

动感超人的专栏 5518

纯干货!PHP专题之开发爬虫(含源代码)

爬虫是一种按照一定的规则,自动地抓取万维网信息的程序或者脚本。 我们平常使用搜索引擎浏览网页,有很多和预期的信息不匹配的结果;并且信息量巨大,有了结果以后还需要花费很大的精力进行筛选信息。爬虫应运诞生,我们可以写一段脚本或程序,让他根据我们的需求按照设定的规则进行抓取网页信息,并筛选出我们需要的结果。 首先,在PHP中可以获取万维网页面的函数有很多,例如:file_get_contents()...

黑马程序员官方博客 1882

采集(file_get_connect)

[html] view plain copy   span style="box-sizing: border-box; color: rgb(102, 102, 102); font-family: 'Microsoft YaHei'; font-size: 15px; line-height: 26px;">span style="box-sizing: borde

dear_zx的博客 816

php用正则表达式获取网站的标题内容

已知网站的网址,用php获取网站的内容。 编写正则表达式。 用preg_match_all函数获取标题内容。 1 $url='http://www.m-ivi.com'; 2 $content=file_get_contents($url); 3 $match='/<title>.*<\/title>/i...

weixin_34267123的博客 428

获取网页内容(不登录_PHP&.NET)

获取网页内容php:$url=http://fund.eastmoney.com/data/FundRankingInfo.html;$str=file_get_contents($url);.net:string url = "http://fund.eastmoney.com/data/FundRankingInfo.html"; WebClient web =

feegle的专栏 522

php 抓取页面数据

$url = 'http://product.dangdang.com/23812052.html'; $str = file_get_contents($url);//抓取函数 preg_match_all('/(? ]) ]*src=[\'"]*([^\'"]*)[\'"][^>]*>(?=[ ])/is', $str , $ar );//正则你想要的数据 $st

Xiao_QiangMa的博客 581

php访问其他网站接口

使用函数: file_get_contents($url); 传入接口url及其参数:如 $url="http://192.168.1.1/test.jsp?id=1&type=2"; $ret=file_get_contents($url); 转载于:https://www.cnblogs.com/carlo-jie/p/7510342.html...

weixin_30731305的博客 454

php中调用其他系统http接口的方法说明

使用函数: file_get_contents($url); 传入接口url及其参数:如 $url="http://192.168.1.1/test.jsp?id=1&type=2"; $ret=file_get_contents($url); 转载于:https://www.cnblogs.com/mssql8/p/4034588.html...

weixin_30548917的博客 152
上一篇: 虚拟主机中让apache显示目录列表的配置方法
下一篇: PHP中str_replace字符串替换函数详解
键盘钢琴师
博客等级 码龄11年 21粉丝 58原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值