php采集网页商品数据库 php数据采集方法

抓取网页数据怎么保存到数据库 php给一个例子你看看吧.
if($pro_list_contents=@file_get_contents(''))
{
preg_match_all("/td width=\"50%\" valign=\"top\"(.*)td width=\"10\"img src=https://www.04ip.com/"images\/spacer.gif\"/isU", $pro_list_contents, $pro_list_contents_ary);
for($i=0; $icount($pro_list_contents_ary[1]); $i++)
{
preg_match_all("/a href=https://www.04ip.com/"(.*)\"img src=https://www.04ip.com/"(.*)\".*span(.*)\/span/isU", $pro_list_contents_ary[1][$i], $url_img_price);
$url=addslashes($url_img_price[1][0]);
$img=str_replace(' ', '20%', trim(''.$url_img_price[2][0]));
$price=(float)str_replace('$', '', $url_img_price[3][0]);
preg_match_all("/a class=\"ml1\" href=https://www.04ip.com/".*\"(.*)\/a/isU", $pro_list_contents_ary[1][$i], $proname_ary);
$proname=addslashes($proname_ary[1][0]);
include("inc/db_connections.php");
$rs=mysql_query("select * from pro where Url='$url' and CateId='{$cate_row['CateId']}'"); //是否已经采集了
if(mysql_num_rows($rs))
{
【php采集网页商品数据库 php数据采集方法】echo "跳过:{$url}br";
continue;
}
$basedir='/u_file/pro/img/'.date('H/');
$save_dir=Build_dir($basedir); //创建目录函数
$ext_name = GetFileExtName( $img); //取得图片后辍名
$SaveName = date( 'mdHis' ) . rand( 10000, 99999 ) . '.' . $ext_name;
if( $get_file=@file_get_contents( $img ) )
{
$fp = @fopen( $save_dir . $SaveName, 'w' );
@fwrite( $fp, $get_file );
@fclose( $fp );
@chmod( $save_dir . $SaveName, 0777 );
@copy( $save_dir . $SaveName, $save_dir . 'small_'.$SaveName );
$imgpath=$basedir.'small_'.$SaveName;
}
else
{
$imgpath='';
}
if($pro_intro_contents=@file_get_contents($url))
{
preg_match_all("/\/h1(.*)\/td\/tr/isU", $pro_intro_contents, $pro_intro_contents_ary);
$p_contents=addslashes(str_replace('src="', 'src="', $pro_intro_contents_ary[1][0]));
$p_contents=SaveRemoteImg($p_contents, '/u_file/pro/intro/'.date('H/')); //把远程html代码里的图片保存到本地
}
$t=time();
mysql_query("insert into pro(CateId, ProName, PicPath_0, S_PicPath_0, Price_0, Contents, AddTime, Url) values('{$cate_row['CateId']}', '$proname', '$imgpath', '$img', '$price', '$p_contents', '$t', '$url')");
echo $url.$img.$cate."br\r\n";
}
}
PHP  , 采集到的数据 , 如何分组放入数据库里面?愚见php采集网页商品数据库:
用函数explode(",",$hq_str_sh601006)
能把字符串按照逗号分开 。可以直接赋值给一个数组变量 。
如:$hq_str_arr=explode(",",$hq_str_sh601006);
然后php采集网页商品数据库你自己可以从数组中按照你获取php采集网页商品数据库的顺序给数组中相应的元素赋值给数据库的对应字段 。
希望有帮助 。
php用正则采集到多个数据如何写入数据库 现在我用php正则采集到了,商品名称title:1,2,3,...n;商品id...个人建议采集到的数据存储为二维数组,其中商品id是唯一的,所以将id作为键值 , 然后每个键值对应的是一个一次包含title,price等数据的二维数组 , 这样采集完成后,可以将这个二维数组遍历循环插入数据库,这样也不容易出现错误
比如其中一个商品id为1,标题为“牙刷” , 价格为$2 , 就这样写入数组$arr[1]=array("牙刷","$2")
怎样借助PHP从HTML网页中获取phpmyadmin数据库里数据表的内容 ?php
$link=mysql_connect('localhost','用户名','密码')or die("数据库连接失败");//连接数据库
mysql_select_db('数据库名',$link);//选择数据库
mysql_query("set names utf8");//设置编码格式
$q="select * from "数据表";//设置查询指令

推荐阅读