- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章PHP中4种常用的抓取网络数据方法由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
本小节的名称为 fsockopen,curl与file_get_contents,具体是探讨这三种方式进行网络数据输入输出的一些汇总。关于 fsockopen 前面已经谈了不少,下面开始转入其它。这里先简单罗列一下一些常见的抓取网络数据的一些方法.
1. 用 file_get_contents 以 get 方式获取内容:
1
2
3
|
$url
=
'http://localhost/test2.php'
;
$html
=
file_get_contents
(
$url
);
echo
$html
;
|
2. 用fopen打开url,以get方式获取内容 。
1
2
3
4
5
6
7
8
9
10
|
$url
=
'http://localhost/test2.php'
;
$fp
=
fopen
(
$url
,
'r'
);
stream_get_meta_data(
$fp
);
$result
=
''
;
while
(!
feof
(
$fp
))
{
$result
.=
fgets
(
$fp
, 1024);
}
echo
"url body: $result"
;
fclose(
$fp
);
|
。
3. 用file_get_contents函数,以post方式获取url 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
$data
=
array
(
'foo'
=>
'bar'
,
'baz'
=>
'boom'
,
'site'
=>
'www.zzvips.com'
,
'name'
=>
'nowa magic'
);
$data
= http_build_query(
$data
);
//$postdata = http_build_query($data);
$options
=
array
(
'http'
=>
array
(
'method'
=>
'POST'
,
'header'
=>
'Content-type:application/x-www-form-urlencoded'
,
'content'
=>
$data
//'timeout' => 60 * 60 // 超时时间(单位:s)
)
);
$url
=
"http://localhost/test2.php"
;
$context
= stream_context_create(
$options
);
$result
=
file_get_contents
(
$url
, false,
$context
);
echo
$result
;
|
4、使用curl库,使用curl库之前,可能需要查看一下php.ini是否已经打开了curl扩展 。
1
2
3
4
5
6
7
8
9
|
$url
=
'http://localhost/test2.php?site=jb51.net'
;
$ch
= curl_init();
$timeout
= 5;
curl_setopt (
$ch
, CURLOPT_URL,
$url
);
curl_setopt (
$ch
, CURLOPT_RETURNTRANSFER, 1);
curl_setopt (
$ch
, CURLOPT_CONNECTTIMEOUT,
$timeout
);
$file_contents
= curl_exec(
$ch
);
curl_close(
$ch
);
echo
$file_contents
;
|
最后此篇关于PHP中4种常用的抓取网络数据方法的文章就讲到这里了,如果你想了解更多关于PHP中4种常用的抓取网络数据方法的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
本文主要给大家介绍Mysql数据库分库和分表方式(常用),涉及到mysql数据库相关知识,对mysql数据库分库分表相关知识感兴趣的朋友一起学习吧 1 分库 1.1 按照功能分库 按照功能进行
在当前对象由其他包含对象操作的系统中,当传递对当前对象的引用时,链接似乎一直在继续......没有任何结束(对于下面的代码,Car ->myCurrentComponent->myCar_Brake-
我有一个密码 UIAlertView,我们要求用户提供。我需要根据情况在不同的 View 上询问它,从 downloadViewController (用户下载数据后),当他们切换到他们的数据时(如果
我正在尝试编写一个函数,使得对于任何整数 x 的 P(x) 都有一个包含三个元素的列表,即平方、立方和 n 的四次方,但我仍然不知道如何组合然后制作一个函数,例如我有平方、立方体和 4 次幂函数下面是
关闭。这个问题需要更多 focused .它目前不接受答案。 关闭4年前。 锁定。这个问题及其答案是locked因为这个问题是题外话,但具有历史意义。它目前不接受新的答案或交互。 我能否列出一份常见的
Python 常用 PEP8 编码规范 代码布局 缩进 每级缩进用4个空格。 括号中使用垂直隐式缩进或使用悬挂缩进。 EXAMPLE: ?
关闭。这个问题需要更多focused .它目前不接受答案。 想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post . 去年关闭。 Improve this questio
在经典 ui 中,您可以使用 xtype:cqinclude 包含来自不同路径的 rtePlugins,基本上为标准 RTE 插件创建一个位置,我如何在 Touch UI 中执行相同操作? 我尝试使用
在经典 ui 中,您可以使用 xtype:cqinclude 包含来自不同路径的 rtePlugins,基本上为标准 RTE 插件创建一个位置,我如何在 Touch UI 中执行相同操作? 我尝试使用
*strong text*我有多个网络应用程序使用了一些常见的依赖项,比如蒙戈连接器谷歌 Guava 乔达时间 我想到将它们从 webapp/WEB-INF/lib 中取出并放入一些 common-l
我正在编写一个 Web 服务器,我想知道哪些 HTTP 请求 header (由客户端发送)是最常见的,因此我应该重点实现。 目前,我只支持Accept 和Host。 最佳答案 不确定您的范围,但由于
我是一名优秀的程序员,十分优秀!