
正文
php采集页面数据入库,php采集网页数据
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
怎么用php程序将页面传过来的数据写入数据库? 代码如下:
就是$insert这条SQL语句的问题
echo $insert;看看语句有没有问题
检查方法将输出的SQL语句放在数据库里执行以下
标准写法
$insert = "insert into my_tab(user,psd) values('".$user."','".$psd."')":
相关问答
Q1: PHP采集入库问题
php 里有$nr = implode(‘#’,$arr) 方法 ,就可以 了
不过上面的组成的是“内容1#内容2”,没有最后面的一个#,要是必须的话
就是$nr = implode('#',$arr).'#'
在笨的方法,就是用
foreach( $arr as $vl){
$nr.=$vl."#";
}
Q2: 如何用Php语言把网页上的文章信息存入mysql数据库的表中
首先,你是不是要做采集.如果是.你要会PHP的正则表达式,去获取页面文章的标题,以及对应的内容,然后分别放到两个变量中。再通过SQL 写到数据库.
Q3: PHP如何采集多个文本并入库?
用一条SQL语句就可以了。
select no,datetime,sum(np),sum(wp) from zdl group by no,datetime
Q4: PHP:把页面的表格数据写入数据库
1,在数据库中建一个表,用来存数据。
2,提交后
php把四个值接收到过然后存进去就行了。
还不懂可以HI我。
Q5: 抓取网页数据怎么保存到数据库 php
给一个例子你看看吧.
if($pro_list_contents=@file_get_contents(''))
{
preg_match_all("/td width=\"50%\" valign=\"top\"(.*)td width=\"10\"img src=\"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=\"(.*)\"img src=\"(.*)\".*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=\".*\"(.*)\/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))
{
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采集网页数据的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







