
正文
php数据采集类实例代码 php数据采集类实例代码怎么写
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
如何用php获取数据库信息并显示
获取ppq数据库的所有表名的代码:
?php
$server='localhost';
$user='root';
$pass='12345';
$dbname='ppq';
$conn=mysql_connect($server,$user,$pass);
if(!$conn)
die("数据库系统连接失败!");
$result=mysql_list_tables($dbname);
if(!$result)
die("数据库连接失败!");
while($row=mysql_fetch_row($result))
{
echo
$row[0]."
";
}
mysql_free_result($result);
?
mysql_list_tables
(PHP
3,
PHP
4
,
PHP
5)
mysql_list_tables
--
列出
MySQL
数据库中的表
说明
resource
mysql_list_tables
(
string
database
[,
resource
link_identifier])
mysql_list_tables()
接受一个数据库名并返回和
mysql_query()
函数很相似的一个结果指针。用
mysql_fetch_array()或者用mysql_fetch_row()来获得一个数组,数组的第0列就是数组名,当获取不到时
mysql_fetch_array()或者用mysql_fetch_row()返回
FALSE。
相关问答
Q1: php中如何延迟执行某段需要采集其他网站数据的代码
添加js代码块,设置或者根据网速自动计算延迟时间就行了啊,或者使用引用页
Q2: php获取天气预报的代码
?php
$URLStyle = "";
$chinaURL = sprintf($URLStyle, "china");
$chinaStr = file_get_contents($chinaURL);
$chinaObj = simplexml_load_string($chinaStr);
$chinaObjLen = count($chinaObj-city);
echo "chinaObjLen = ".$chinaObjLen."\n";
for ($i=0;$i$chinaObjLen;$i++){
//遍历省一级节点php数据采集类实例代码,共37个
$level1 = $chinaObj-city[$i]["pyName"];
$shengjiURL = sprintf($URLStyle, $level1);
$shengjiStr = file_get_contents($shengjiURL);
//echo $shengjiStr;
$shengjiObj = simplexml_load_string($shengjiStr);
$shengjiObjLen = count($shengjiObj-city);
// echo $chinaObj-city[$i]["quName"];
// echo " ".$shengjiObjLen."\n";
for ($j=0;$j$shengjiObjLen;$j++){
//遍历市一级节点
$level2 = $shengjiObj-city[$j]["pyName"];
$shijiURL = sprintf($URLStyle, $level2);
$shijiStr = file_get_contents($shijiURL);
//echo $shijiStr;
$shijiObj = simplexml_load_string($shijiStr);
//直辖市和海南、台湾、钓鱼岛等没有县级节点
if(!$shijiObj){
echo "WARNNING: not exsit next level node. - ".$level1."-".$shijiURL."\n";
echo ' "'.$shengjiObj-city[$j]["cityname"].'" = ';
echo $shengjiObj-city[$j]["url"].",\n";
continue;
}
$shijiObjLen = count($shijiObj-city);
//echo $shengjiObj-city[$j]["cityname"]." ";
//echo $shijiObjLen."\n";
for ($k=0;$k$shijiObjLen;$k++){
//遍历县一级节点
$xianji_code = $shijiObj-city[$k]["url"];
echo ' "'.$shijiObj-city[$k]["cityname"].'" = ';
echo $shijiObj-city[$k]["url"].",\n";
//echo $xianji_code."\n";
}
}
}
//print_r($chinaObj);
?
通过XML接口根节点递归获得全国几千个县以上城市cide codephp数据采集类实例代码的代码
Q3: 怎么用php采集网站数据
简单的分了几个步骤:
1、确定采集目标
2、获取目标远程页面内容(curl、file_get_contents)
3、分析页面html源码,正则匹配你需要的内容(preg_match、preg_match_all),这一步最为重要,不同页面正则匹配规则不一样
4、入库
Q4: php如何获取数据库信息
代码如下php数据采集类实例代码:?View
Code
PHP
include("conn.php");//调用数据库连接文件
echo
"table
width=572
height=56
border=0
cellspacing=1
";
//创建html表格
echo
"tr
bgcolor=#9999FF";
echo
"th
width=33
scope=colid/th";
echo
"th
width=100
scope=coluser_name/th
";
echo
"th
width=100
scope=coluser_pass/th
";
echo
"th
width=100
scope=colstaus/th";
echo
"th
width=100
scope=colinsert_time/th";
echo
"/tr";
$SQL
=
"select
*
from
user_info";
$query
=
mysql_query($SQL);
//SQL查询语句
while
($row
=
mysql_fetch_array($query)){
//使用while循环mysql_fetch_array()并将数据返回数组
echo
"tr
onmouseout=this.style.backgroundColor=''
onMouseOver=this.style.backgroundColor='#99CC33'
bgcolor=#CCCCCC";
echo
"td$row[0]/td";
//输出数组中数据
echo
"td$row[1]/td";
echo
"td$row[2]/td";
echo
"td$row[3]/td";
echo
"td$row[4]/td";
echo
"/tr";
}
echo
"/table";输出记录截图
Q5: php 百度 知道数据采集
问题其实不难,自己都能写。给你几个思路吧:
1.在百度知道中,输入linux,然后会出现列表。复制浏览器地址栏内容。
然后翻页,在复制地址栏内容,看看有什么不同,不同之处,就是你要循环分页的i值。
当然这个是笨方法。
2.使用php的file或者file_get_contents函数,获取链接URL的内容。
3.通过php正则表达式,获取你需要的3个字段内容。
4.写入数据库。
需要注意的是,百度知道有可能做了防抓取的功能,你刚一抓几个页面,可能会被禁止。
建议也就抓10页数据。
其实不难,你肯定写的出来。 还有,网上应该有很多抓取工具,你找找看,然后将抓下来的数据
在做分析。写入数据库。
关于php数据采集类实例代码和php数据采集类实例代码怎么写的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







