php抓取数据存入sql php抓取网页数据

PHP获取网站中的信息并存入数据库用PHP自带函数就可以实现,首先要过去对方的网页信息,用
file_get_contents();参数是对方的URL地址,这个函数返回是一个字符串你想要的东西就在这个字符串中了
接下来就可以针对这个字符串做处理了,说下思路,正如你这个问题想获取到航班号起飞时间,在这个网页中应该有很多相同的标签元素,它们都有共同点 , 用
用正则表达式preg_match();或者是
preg_match_all();这两个函数它们都返回一个数组,这个数组存的就是你要的航班号和起飞时间,那么相同信息的数组就会出现了,然后在对这个数组进行分析找到你要的某个值或全部的值
获取信息要用到的3个函数是:
file_get_contents();
preg_match();
preg_match_all();
PHP如何将文本域保存到SQL数据库给你说个思路吧,你在html页面里面写
html页面
form action="1.php" method="post"
input type="text" name="name"
input type="submit" value="https://www.04ip.com/post/Submit"
/form
i.php页面
获取到文本值,然后插入到数据库就行了
php读取sql文件导入数据库这样写就不会错了,看看能否帮到php抓取数据存入sql你
form id="form1" name="form1" method="post" action="" enctype="multipart/form-data"
input type="file" name="textfield" id="textfield" /
input type="submit" name="button" id="button" value="https://www.04ip.com/post/提交" /
/form
?
if($_POST['button']!=""){
$url=$_FILES['textfield']['tmp_name'];//获取上传来php抓取数据存入sql的文件地址
$sql=file_get_contents($url);//打开文件
sql($sql);//执行读取函数
}
function sql($sql){
$conn=mysql_pconnect("localhost","root","123456");
mysql_select_db("shop",$conn);
mysql_query("set names utf8");
$R=mysql_query($sql);
while($v=mysql_fetch_array($R)){
echo $v['ai_id'];
echo "hr";
}
}
//sql($sql);
?
抓取网页数据怎么保存到数据库 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]));
【php抓取数据存入sql php抓取网页数据】$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))
{
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中将Form表单中的数据提交到SQL数据库你好,首先你要在php页面中有处理post过来的代码 , 将post过来的值写入数据库,如果是在当前页面处理数据 , (你这个是当前页面)那在submit里加name="tj"(name的值随你)写入数据库:if(isset($_POST[''])){首先连接你的数据库;$sql="insert into 表名 values(‘$_POST[head]’,'$_POST[name]'.'根据你实际的数据库设计和表单提交过来的值写')“;}在radioinfo.php里,首先还是连接数据库 , 然后执行查询语句,$sql_1="select * from 表名 where 条件”;$result=mysql_query($sql_1);$row=mysql_fetch_row($result);($row为数组)echo $row[0];//echo 想出你需要的值
想请问下PHP怎么实现从网络API接口上获取显示的字符数据,存储到MySQL数据库1.修改PHP配置文件,保证能够连接到数据库 。
2.修改数据库配置 , 授予192.168.1.253以访问权限 。这里只需授予这个IP就行了 。如果不授予,PHP将不能访问数据库;如果授予范围过广 , 将会给你的系统带来潜在的安全风险 。
关于php抓取数据存入sql和php抓取网页数据的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读