php提取网页指定数据 php提取网页内容

PHP用curl获取到的网页怎么取出其中的类似数据

试试这个方法:

网站建设哪家好,找成都创新互联!专注于网页设计、网站建设、微信开发、微信小程序、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了岐山免费建站欢迎大家使用!

fnServerData": function ( sSource, aoData, fnCallback ) {

/* Add some extra data to the sender */

aoData.push( { "name": "more_data", "value": "my_value" } );

$.getJSON( sSource, aoData, function (json) {

/* Do whatever additional processing you want on the callback, then tell DataTables */

fnCallback(json)

} );

}

PHP抓取网页指定内容

?php

/*

* 如下: 方法有点笨

* 抓取网页内容用 PHP 的正则

* 用JS每隔5分钟刷新当前页面---即重新获取网页内容

*

* 注: $mode中--title/title-更改为所需内容(如 $mode = "#a(.*)/a#";获取所有链接)

*

* window.location.href="";中的

* 更改为自己的URL----作用:即刷新当前页面

*

* setInterval("ref()",300000);是每隔300000毫秒(即 5 * 60 *1000 毫秒即5分钟)执行一次函数 ref()

*

* print_r($arr);输出获得的所有内容 $arr是一个数组 可根据所需输出一部分(如 echo $arr[1][0];)

* 若要获得所有内容 可去掉

* $mode = "#title(.*)/title#";

if(preg_match_all($mode,$content,$arr)){

print_r($arr);

echo "br/";

echo $arr[1][0];

}

再加上 echo $content;

*/

$url = ""; //目标站

$fp = @fopen($url, "r") or die("超时");

$content=file_get_contents($url);

$mode = "#title(.*)/title#";

if(preg_match_all($mode,$content,$arr)){

//print_r($arr);

echo "br/";

echo $arr[1][0];

}

?

script language="JavaScript" type="text/javascript"

--

function ref(){

window.location.href="";

}

setInterval("ref()",300000);

//--

/script

用PHP获取网页部分数据

如果你要

之间的所有源码,用 preg_match 就可以,不用preg_match_all ,如果你要里面的所有的

标签中的内容,可以用preg_match_all //提取所有代码 $pattern = '/

(.+?)

/is'; preg_match($pattern, $string, $match); //$match[0] 即为

之间的所有源码 echo $match[0]; //然后再提取

之间的内容 $pattern = '/(.+?)li/is'; preg_match_all($pattern, $match[0], $results); $new_arr=array_unique($results[0]); foreach($new_arr as $kkk){ echo $kkk; }

PHP怎样抓取网页代码中动态显示的数据

PHP Simple HTML DOM或者phpQuery可以直接取得某些div中的内容,里面有几个例子专门针对于网页抓取,调整好抓取频次,舍去已经存在的数据,你可以参考下

;id=57class=2

怎么用php采集网站数据

简单的分了几个步骤:

1、确定采集目标

2、获取目标远程页面内容(curl、file_get_contents)

3、分析页面html源码,正则匹配你需要的内容(preg_match、preg_match_all),这一步最为重要,不同页面正则匹配规则不一样

4、入库

利用PHP Simple HTML DOM获取网页指定数据 名称和链接

抓取页面上的列表数据,以及内容里面信息

1 ?php

2 include_once 'simple_html_dom.php';

3 //获取html数据转化为对象

4 $html = file_get_html('');

5 //A-Z的字母列表每条数据是在id=letter-focus 的div内class= letter-focus-item的dl标签内,用find方法查找即为

6 $listData=$html-find("#letter-focus .letter-focus-item");//$listData为数组对象

7 foreach($listData as$key=$eachRowData){

8 $filmName=$eachRowData-find("dd span",0)-plaintext;//获取影视名称

9 $filmUrl=$eachRowData-find("dd a",0)-href;//获取dd标签下影视对应的地址

10 //获取影视的详细信息

11 $filmInfo=file_get_html("".$filmUrl);

12 $filmDetail=$filmInfo-find(".info dl");

13 foreach($filmDetail as $film){

14 $info=$film-find("dd");

15 $row=null;

16 foreach($info as $childInfo){

17 $row[]=$childInfo-plaintext;

18 }

19 $cate[$key][]=join(",",$row);//将影视的信息存放到数组中

20 }

21 }

这样通过simple_html_dom,就可以将paopaotv.com影视列表中信息,以及影视的具体信息就抓取到了,之后你可以继续抓取影视详细页面上的视频地址信息,然后将该影视的所有信息都存放到数据库中。

下面是simple_html_dom常用的属性以及方法:

1 $html = file_get_html('');

2 $e = $html-find("div", 0);

3 //标签

4 $e-tag;

5 //外文本

6 $e-outertext;

7 //内文本

8 $e-innertext;

9 //纯文本

10 $e-plaintext;

11 //子元素

12 $e-children ( [int $index] );

13 //父元素

14 $e-parent ();

15 //第一个子元素

16 $e-first_child ();

17 //最后一个子元素

18 $e-last_child ();

19 //后一个兄弟元素

20 $e-next_sibling ();

21 //前一个兄弟元素

22 $e-prev_sibling ();

23 //标签数组

24 $ret = $html-find('a');

25 //第一个a标签

26 $ret = $html-find('a', 0);


名称栏目:php提取网页指定数据 php提取网页内容
新闻来源:http://ybzwz.com/article/hpgeip.html