网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

php网页表格数据采集 php获取excel单元格数据

怎样借助PHP从HTML网页中获取phpmyadmin数据库里数据表的内容

?php

成都创新互联公司是一家集成都网站制作、成都做网站、外贸营销网站建设、网站页面设计、网站优化SEO优化为一体的专业网络公司,已为成都等多地近百家企业提供网站建设服务。追求良好的浏览体验,以探求精品塑造与理念升华,设计最适合用户的网站页面。 合作只是第一步,服务才是根本,我们始终坚持讲诚信,负责任的原则,为您进行细心、贴心、认真的服务,与众多客户在蓬勃发展的市场环境中,互促共生。

$link=mysql_connect('localhost','用户名','密码')or die("数据库连接失败");//连接数据库

mysql_select_db('数据库名',$link);//选择数据库

mysql_query("set names utf8");//设置编码格式

$q="select * from "数据表";//设置查询指令

$result=mysql_query($q);//执行查询

while($row=mysql_fetch_assoc($result))//将result结果集中查询结果取出一条

{ echo  返回到HTML; }

?

html界面使用ajax的成功返回值,再渲染在界面里就行了

怎么用php采集网站数据

简单的分了几个步骤:

1、确定采集目标

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

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

4、入库

PHP 采集程序中常用的函数

复制代码

代码如下:

//获得当前的脚本网址

function

get_php_url()

{

if(!empty($_SERVER[”REQUEST_URI”]))

{

$scriptName

=

$_SERVER[”REQUEST_URI”];

$nowurl

=

$scriptName;

}

else

{

$scriptName

=

$_SERVER[”PHP_SELF”];

if(empty($_SERVER[”QUERY_STRING”]))

$nowurl

=

$scriptName;

else

$nowurl

=

$scriptName.”?”.$_SERVER[”QUERY_STRING”];

}

return

$nowurl;

}

//把全角数字转为半角数字

function

GetAlabNum($fnum)

{

$nums

=

array(”0”,”1”,”2”,”3”,”4”,”5”,”6”,”7”,”8”,”9”);

$fnums

=

“0123456789″;

for($i=0;$i=9;$i++)

$fnum

=

str_replace($nums[$i],$fnums[$i],$fnum);

$fnum

=

ereg_replace(”[^0-9\.]|^0{1,}”,””,$fnum);

if($fnum==””)

$fnum=0;

return

$fnum;

}

//去除HTML标记

function

Text2Html($txt)

{

$txt

=

str_replace(”

“,” ”,$txt);

$txt

=

str_replace(””,””,$txt);

$txt

=

str_replace(””,””,$txt);

$txt

=

preg_replace(”/[\r\n]{1,}/isU”,”br/\r\n”,$txt);

return

$txt;

}

//清除HTML标记

function

ClearHtml($str)

{

$str

=

str_replace('','',$str);

$str

=

str_replace('','',$str);

return

$str;

}

//相对路径转化成绝对路径

function

relative_to_absolute($content,

$feed_url)

{

preg_match('/(http|https|ftp):\/\//',

$feed_url,

$protocol);

$server_url

=

preg_replace(”/(http|https|ftp|news):\/\//”,

“”,

$feed_url);

$server_url

=

preg_replace(”/\/.*/”,

“”,

$server_url);

if

($server_url

==

”)

{

return

$content;

}

if

(isset($protocol[0]))

{

$new_content

=

preg_replace('/href=”\//',

‘href=”‘.$protocol[0].$server_url.'/',

$content);

$new_content

=

preg_replace('/src=”\//',

'src=”‘.$protocol[0].$server_url.'/',

$new_content);

}

else

{

$new_content

=

$content;

}

return

$new_content;

}

//取得所有链接

function

get_all_url($code){

preg_match_all('/a\s+href=[”|\']?([^”\'

]+)[”|\']?\s*[^]*([^]+)\/a/i',$code,$arr);

return

array('name'=$arr[2],'url'=$arr[1]);

}

//获取指定标记中的内容

function

get_tag_data($str,

$start,

$end)

{

if

(

$start

==

||

$end

==

)

{

return;

}

$str

=

explode($start,

$str);

$str

=

explode($end,

$str[1]);

return

$str[0];

}

//HTML表格的每行转为CSV格式数组

function

get_tr_array($table)

{

$table

=

preg_replace(”‘td[^]*?'si”,'”‘,$table);

$table

=

str_replace(”/td”,'”,',$table);

$table

=

str_replace(”/tr”,”{tr}”,$table);

//去掉

HTML

标记

$table

=

preg_replace(”‘[\/\!]*?[^]*?'si”,””,$table);

//去掉空白字符

$table

=

preg_replace(”‘([\r\n])[\s]+'”,””,$table);

$table

=

str_replace(”

“,””,$table);

$table

=

str_replace(”

“,””,$table);

$table

=

explode(”,{tr}”,$table);

array_pop($table);

return

$table;

}

//将HTML表格的每行每列转为数组,采集表格数据

function

get_td_array($table)

{

$table

=

preg_replace(”‘table[^]*?'si”,””,$table);

$table

=

preg_replace(”‘tr[^]*?'si”,””,$table);

$table

=

preg_replace(”‘td[^]*?'si”,””,$table);

$table

=

str_replace(”/tr”,”{tr}”,$table);

$table

=

str_replace(”/td”,”{td}”,$table);

//去掉

HTML

标记

$table

=

preg_replace(”‘[\/\!]*?[^]*?'si”,””,$table);

//去掉空白字符

$table

=

preg_replace(”‘([\r\n])[\s]+'”,””,$table);

$table

=

str_replace(”

“,””,$table);

$table

=

str_replace(”

“,””,$table);

$table

=

explode('{tr}',

$table);

array_pop($table);

foreach

($table

as

$key=$tr)

{

$td

=

explode('{td}',

$tr);

array_pop($td);

$td_array[]

=

$td;

}

return

$td_array;

}

//返回字符串中的所有单词

$distinct=true

去除重复

function

split_en_str($str,$distinct=true)

{

preg_match_all('/([a-zA-Z]+)/',$str,$match);

if

($distinct

==

true)

{

$match[1]

=

array_unique($match[1]);

}

sort($match[1]);

return

$match[1];

}

PHP 获取网页中用户输入的数据的函数

用户在表格form

中填写数据,然后提交到一个php文件,PHP文件使用函数获取数据

form action="welcome.php" method="post"

Name: input type="text" name="name"br

E-mail: input type="text" name="email"br

input type="submit" value="提交"

/form用户填写完username后提交到welcome.php文件,在welcome.php文件中,

html

body

Welcome ?php echo $_POST["name"]; ?br

Your email address is: ?php echo $_POST["email"]; ?

/body

/html$_POST["name"]就是用户输入的名字

PHP获取页面表格里单元格的内容

由于你没给出具体的页面,我只能给你一个通用的获取方法,有些页面可能有多个表格,这时需要你多加一些参数进行过滤了,其实个人首推正则匹配获取,示例代码:

$url = "";    //换成你自己需要获取的页面地址

$content = file_get_contents($url);

preg_matches("/table([.\n]+)\/table/",$contents,$matches);

echo $matches[0]; //即为表单内容

如何用Excel进行网页数据采集

excel采集互联网信息

用EXCEL采集网页信息,其实并不难,需要开启宏功能,用VBA编写采集代码,就可以将信息采集到表格里了。

Function ReadWeb(strURL)

以下是关键代码:编写一个采集函数

' MsgBox strURL

'Range("H2").Value = strURL

t = Timer '开始计时

tt = t

nm = Left(Range("J3").Value, 2) Range("J4").Value

url2 = "https://**.com.cn/**.php?symbol=" nm 

Set objWeb = CreateObject("MSXML2.XMLHTTP") 'Microsoft.XMLHTTP

objWeb.Open "Get", strURL, False, "", ""

objWeb.send

arrBytes = CStr(objWeb.responseBody) 

mytime2 = mytime2 + Timer - tt '计时 

strReturn = "" '以下将二进制数据流转换为中文文本

For i = 1 To LenB(arrBytes)

  Chr1 = AscB(MidB(arrBytes, i, 1))

  If Chr1 H80 Then

      strReturn = strReturn Chr(Chr1)

      Else

      Chr2 = AscB(MidB(arrBytes, i + 1, 1))

      strReturn = strReturn Chr(CLng(Chr1) * H100 + CInt(Chr2))

      i = i + 1

  End If

Next i

 ReadWeb = strReturn

End Function


网页标题:php网页表格数据采集 php获取excel单元格数据
浏览地址:http://bjjierui.cn/article/dososdp.html

其他资讯